doqo89924 2013-06-18 08:16
浏览 38

remove smarty - >在prestashop中从控制器分配变量

I modified the default prestashop 1.5 newsletter module and made the following override of to the IdentityController

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

So the checkbox would appear to set/unset newsletter subscription via the "my personal information" account link.

Everything works fine but with ini_set("display_errors", 1); i still get the following php error on the personal info page

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.

line 135 of IdentityController.php is

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

When i comment out the line, the error goes away, but I really don't want to mess with the core files, can anyone tell me how to "unset" this variable through the override file?

  • 写回答

1条回答 默认 最新

  • dongtaoxue4674 2013-09-04 18:57
    关注

    Create file IdentityController.php in override/controllers/front/.

    Now copy the method you are having problem with into this file and comment line with faulty code.

    You also want to delete file tools/smarty/index.php to force smarty template recompilation! (Rookie mistake)

    For your information, this notice is thrown because you are trying to access variable named "active" of object that does not exist.

    This is accessing public attribute:

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

    This is calling public static method of class Module:

    Module::getInstanceByName('blocknewsletter');
    

    In this call no object is really created because non is needed.

    Thankfully passing non-existing variable into smarty template isn't fatal error and application can keep running ignoring this mistake.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题