PHP 与聪明=>无法访问 .tpl 文件中的附加变量
我试图通过以以下形式分配 SMARTY 变量 $error
来显示错误消息:
function validate1() {
$error['title'] = "Title contains illegal characters...";
$this->smarty->append('error', $error);
}
function validate2() {
$error['time'] = "Please enter a time in 12 hour clock (12:30 PM) format.";
$this->smarty->append('error', $error);
}
我的 HTML 如下所示:
<p class="message-error">{$error['title']}</p>
<p class="message-error">{$error['time']}</p>
我最近一直在使用下面的代码,该代码有效;有什么方法可以修改第一段代码以使其与下面的代码相同?
$error['title'] = "Title contains illegal characters...";
$error['time'] = "Please enter a time in 12 hour clock (12:30 PM) format.";
$this->smarty->assign("error", $error);
I am trying to display error messages by assigning the SMARTY variable $error
in the form of:
function validate1() {
$error['title'] = "Title contains illegal characters...";
$this->smarty->append('error', $error);
}
function validate2() {
$error['time'] = "Please enter a time in 12 hour clock (12:30 PM) format.";
$this->smarty->append('error', $error);
}
My HTML looks like:
<p class="message-error">{$error['title']}</p>
<p class="message-error">{$error['time']}</p>
I had recently been using the code below, which works; is there any way that I can modify the first block of code to work the same as the code below?
$error['title'] = "Title contains illegal characters...";
$error['time'] = "Please enter a time in 12 hour clock (12:30 PM) format.";
$this->smarty->assign("error", $error);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您以这种方式定义数组并包含合并选项(
append()
的第三个参数),它是否有效编辑忘记包含合并参数。
Does it work if you define the array this way and include the merge option (3rd param to
append()
)EDIT Forgot to include the merge parameter.
阅读 smarty 手册,正确的语法关联数组是:
Read smarty manual, correct syntax for associative arrays is: