我有這樣的Smarty代碼:的Smarty的foreach白頁
{foreach from=$chats item=chat}
{$chat['id']}
{/foreach}
當我嘗試執行此,我得到一個白色的頁面。
我檢查,如果PHP代碼通過一個合法的陣列
{$chats[0]['id']}
而這個工作。
我想Smarty應該輸出一個錯誤,如果有什麼問題,所以我檢查了我的Smarty設置,但他們似乎沒關係?
<?php
require('smarty/Smarty.class.php');
global $smarty;
error_reporting(E_ALL);
ini_set('display_errors', '1');
$smarty = new Smarty();
$smarty->error_reporting = E_ALL & ~E_NOTICE;
$smarty->debugging = true;
$smarty->template_dir = "templates";
$smarty->compile_dir = "templates_c";
$smarty->cache_dir = "cache";
$smarty->config_dir = "configs";
?>
我檢查了我的Smarty安裝:
Smarty Installation test...
Testing template directory...
\templates is OK.
Testing compile directory...
\templates_c is OK.
Testing plugins directory...
\plugins is OK.
Testing cache directory...
\cache is OK.
Testing configs directory...
\configs is OK.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.
沒有foreach語句,一切正常。
更新
我有Smarty的版本3.1.13,
我試過了這個例子的代碼,從Smarty的文檔(http://www.smarty.net/docs/en/language.function.foreach.tpl):
<?php
require("smarty.php");
$arr = array('red', 'green', 'blue');
$smarty->assign('myColors', $arr);
$smarty->display('foreach.tpl');
?>
<ul>
{foreach $myColors as $color}
<li>{$color}</li>
{/foreach}
</ul>
但即使有這樣的代碼全部我得到的是一個白頁
沒有'foreach'頁面工作嗎?我的意思是'foreach'上的問題?你可以試試'{$ chat.id}' – waki