PHP 与聪明=>无法访问 .tpl 文件中的附加变量

发布于 2024-11-25 00:08:25 字数 794 浏览 5 评论 0原文

我试图通过以以下形式分配 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久而酒知 2024-12-02 00:08:25

如果您以这种方式定义数组并包含合并选项(append() 的第三个参数),它是否有效

function validate1() {
  $error = array('title' => "Title contains illegal characters...");
  $this->smarty->append('error', $error, TRUE);
  // -------------------------------------^^^^
}

编辑忘记包含合并参数。

Does it work if you define the array this way and include the merge option (3rd param to append())

function validate1() {
  $error = array('title' => "Title contains illegal characters...");
  $this->smarty->append('error', $error, TRUE);
  // -------------------------------------^^^^
}

EDIT Forgot to include the merge parameter.

撩心不撩汉 2024-12-02 00:08:25

阅读 smarty 手册,正确的语法关联数组是:

{$error.title}

Read smarty manual, correct syntax for associative arrays is:

{$error.title}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文