Smarty로 실험을하고 있는데 foreach 루프에 문제가 있습니다. 작동하지 않고 이유를 이해할 수 없습니다.Smarty foreach가 작동하지 않습니다.
Default.tpl 나는 다음과 같은 오류가 테스트 할 때
<select name="user">
{html_options values=$id output=$names selected="5"}
</select>
<table>
{foreach $names as $name}
{strip}
<tr bgcolor="{cycle values='#eeeeee,#dddddd'}">
<td>{$name}</td>
</tr>
{/strip}
{/foreach}
</table>
<table>
{foreach $users as $user}
{strip}
<tr bgcolor="{cycle values='#aaaaaa,#bbbbbb'}">
<td>{$user.name}</td>
<td>{$user.phone}</td>
</tr>
{/strip}
{/foreach}
</table>
하고
<?php
include('Smarty.class.php');
//create object
$smarty = new Smarty;
$smarty->template_dir = 'C:\xampp\htdocs\smarty\templates';
$smarty->config_dir = 'C:\xampp\htdocs\smarty\config';
$smarty->cache_dir = 'C:\xampp\php\smarty\cache';
$smarty->compile_dir = 'C:\xampp\php\smarty\templates_c';
$smarty->assign('names', array('Bob', 'Jimmy', 'Freddy', 'Walter', 'Jerry'));
$smarty->assign('users', array(
array('name' => 'bob', 'phone' => '555-3425'),
array('name' => 'jim', 'phone' => '555-4364'),
array('name' => 'joe', 'phone' => '555-3422'),
array('name' => 'jerry', 'phone' => '555-4973'),
array('name' => 'fred', 'phone' => '555-3235')
));
//display information
$smarty->display('default.tpl');
?>
을 default.php : 여기 내 코드는
치명적인 오류 : 멋지 오류 : [기본에 .tpl line 16] : 구문 오류 : 1094 줄의 C : \ xampp \ php \ Smarty \ libs \ Smarty.class.php에있는 '$ names'(Smarty_Compiler.class.php, 1550 줄)이 잘못되었습니다.
$ 사용자에게도 마찬가지입니다. 값이 지나가고 있다는 것을 알고 있기 때문에, 작동하고 있기 때문에, 나는 무슨 일이 일어나고 있는지 이해할 수 없다.
Thnx.
편집 : 나는 멋진 웹 사이트에서이 예를 들었습니다.
Smarty3에서 도입 한 구문을 사용하고 있지만 실제로는 Smarty2가 실행 중입니다. Smarty3로 업그레이드 (현재 3.1.12) 또는 foreach를'{foreach from = $ users item = user} '로 변경하십시오. – rodneyrehm