【发布时间】:2014-04-19 01:38:35
【问题描述】:
我有这个 Smarty 代码:
{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}