删除smarty ->在prestshop中从控制器分配变量


remove smarty -> assign variable from controller in prestashop

我修改了默认的prestshop 1.5 newsletter模块,并对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);

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

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

现在把你有问题的方法复制到这个文件中,并用错误的代码注释行。

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

为您的信息,这个通知被抛出,因为您试图访问变量名为"active"的对象,不存在。

这是访问公共属性:

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

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

Module::getInstanceByName('blocknewsletter');

在这个调用中没有真正创建对象,因为需要non。

值得庆幸的是,将不存在的变量传递给smarty模板并不是致命错误,应用程序可以忽略这个错误继续运行。