我实际上是在Prestashop 1.5中使用Tools class,它使我可以向前端显示错误消息:
$this->errors[] = Tools::displayError( 'Fatal error!' );
是否有任何功能以相同的方式显示成功消息?似乎我们无法在扩展的l()
ModuleFrontController()
函数任何建议将不胜感激。
您显示错误/成功消息的方式,如下所示:
{if isset($success)}
<p class="success">{$success}</p>
{/if}
是不错的选择。请注意
Tools::displayError('Fatal error');
没有为您提供错误消息的任何样式,它只是提供了一种在admin处翻译错误的方法。
如果您还希望成功消息也可以翻译,那么请在您的控制器中按照以下说明进行操作:
$this->context->smarty->assign( 'success', 1 );
然后在您的模板文件中
{if isset($success)}
{l s='This is success message'}
{/if}
并且如果模板文件在模块中,则将其用作
{if isset($success)}
{l s='This is success message' mod='yourmodulename'}
{/if}
希望这会对您有所帮助。
谢谢
找到了解决方案,但这可能不是最好的:
在我的ModuleFrontController()
类里面:
$this->context->smarty->assign( 'success', 'Success!' );
在模块的模板文件顶部:
{if isset($success)}
<p class="success">{$success}</p>
{/if}
它显示“成功!”如预期。
对于成功消息,您可以使用:
$output = null;
$output .= $this->displayConfirmation('<message goes here!>');
对于错误消息,您可以使用:
$output = null;
$output .= $this->displayError('<message goes here!>');
最后一个:
return $output;
或类似的东西:
return $output.$this->displayForm();
它在PrestaShop 1.7中对我有用
$this->errors[] = "Error message!";
$this->success[] = "Success message!";