强制Smarty显示PHP错误

时间:2012-11-28 13:39:11

标签: php smarty prestashop

我一直在使用PHP一段时间,但对Smarty来说还是比较新的。

我正在使用Prestashop,我注意到Smarty似乎吃掉了所有PHP错误 - 当PHP代码出错时,.tpl文件只输出一个空白页面。我一直在尝试,但即使出现错误,我也无法让Smarty显示PHP代码输出的任何内容。

PHP错误报告设置为显示错误。

因此,举个例子,假设这是example.php文件:

<?php
//included classes etc go here, irrelevant for this issue

error_reporting(E_ALL ^ E_NOTICE);

echo obvious wrong syntax"
?>

此文件连接到example.tpl,它适合模板块中的输出。

显然,它应该抛出一个错误。如何让Smarty实际显示该错误?

3 个答案:

答案 0 :(得分:13)

要激活调试模式,请转到config/config.inc.php

找到以下行并将off变为on作为第一行并将其设置为true作为第二行

/* Debug only */
@ini_set('display_errors', 'on');
define('_PS_DEBUG_SQL_', true);

这将显示PHP和SQL错误(这可能足以让您解析“空白页面”)。

还有blog post on prestashop site about p() and d() methods and how to track exceptions

要在早于1.5的Prestashop版本中激活模板调试,请转至config / smarty.config.inc.php

找到以下行并将其设置为true

$smarty->debugging = true;

刷新页面时,应呈现themes/debug.tpl

要在Prestashop 1.5+中激活模板调试,您可以通过管理面板启用Smarty调试

  

偏好设置&gt;表现&gt; Smarty

并设置Always open console,但会为所有人打开控制台(不适合现场网站:)

或设置Open console with URL parameter (SMARTY_DEBUG)并在网址末尾添加?SMARTY_DEBUG以查看控制台

希望这有帮助。

答案 1 :(得分:1)

我已经看到了@Sergei Guk的回答,当然,这是一个非常好的答案。但是,prestashop已经发布了1.6版本。

因此,如果你想在prestashop v 1.6.0.6中显示所有错误,你只需要去config / defines.inc.php

define('_PS_MODE_DEV_', false);替换为define('_PS_MODE_DEV_', true);

它实际上做的是设置一个常量,并在下一行检查“_PS_MODE_DEV_”是否为真,然后它将在prestashop中显示各种错误

if (_PS_MODE_DEV_)
{
  @ini_set('display_errors', 'on');
  @error_reporting(E_ALL | E_STRICT);
  define('_PS_DEBUG_SQL_', true);
}
else
{
  @ini_set('display_errors', 'off');
  define('_PS_DEBUG_SQL_', false);
}

我测试了它,它工作正常。

答案 2 :(得分:0)

设置$error_reporting变量。

请参阅http://www.smarty.net/docsv2/en/variable.error.reporting.tpl