【问题标题】:remove smarty -> assign variable from controller in prestashop从 prestashop 的控制器中删除 smarty -> 分配变量
【发布时间】:2013-06-18 08:16:39
【问题描述】:

我修改了默认的 prestashop 1.5 通讯模块,并对 IdentityController 进行了以下覆盖

$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('modifiednewsletter')->active);

因此,该复选框将显示为通过“我的个人信息”帐户链接设置/取消订阅时事通讯。

一切正常,但使用ini_set("display_errors", 1); 我仍然在个人信息页面上收到以下 php 错误

Notice: Trying to get property of non-object in /var/www/prestashop/controllers/front/IdentityController.php on line 135 Call Stack: 0.0001 646712 1.

IdentityController.php 的第 135 行是

$this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active);

当我注释掉该行时,错误消失了,但我真的不想弄乱核心文件,谁能告诉我如何通过覆盖文件“取消设置”这个变量?

【问题讨论】:

  • 你能告诉我们你在哪里添加了这段代码吗?你用什么方法使用它,你还做什么?你调用父类的方法吗?
  • public function initContent() { parent::initContent(); $this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('berlindisplaynewsletter')->active); } 我确实调用了父级的方法,因为如果我不这样做,一半的页面不起作用,也许我应该在覆盖中使用新函数而不是 initContent() ?我对 php 和 prestashop 还很陌生,所以我只是在不知道自己在做什么的情况下完成了这一切......

标签: php smarty prestashop


【解决方案1】:

override/controllers/front/中创建文件IdentityController.php

现在将您遇到问题的方法复制到此文件中,并用错误代码注释行。

你还想删除文件 tools/smarty/index.php 来强制 smarty 模板重新编译!(菜鸟错误)

为了您的信息,抛出此通知是因为您试图访问名为“活动”的变量,但该对象不存在。

这是访问公共属性:

$instance = new Module;
$instance->active;

这是调用类Module的公共静态方法:

Module::getInstanceByName('blocknewsletter');

在此调用中,没有真正创建对象,因为不需要。

谢天谢地,将不存在的变量传递给 smarty 模板并不是致命错误,应用程序可以继续运行而忽略此错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多