2

I know there are similar questions, but none of them can solve my problem.

I placed a FrontController.php file in /override/classes/controller/

It contains this code:

Class FrontController extends FrontControllerCore{
    public function displayHeader(){
        if(!self::$initialized) $this->init();

        $this->context->smarty->assign('test_ok','okok');

        return parent::displayHeader();       
    } 
}//end FrontController

From my custom theme, in header.tpl I placed a test code like this

{$test_ok}

And get this:

Notice: Undefined index: test_ok in [...]/cache/smarty/compile/81/a3/76/81a3760f9c0cb8c9ff677a0e7b59d8962cdaaeda.file.header.tpl.php on line 147

Notice: Trying to get property of non-object in [...]/cache/smarty/compile/81/a3/76/81a3760f9c0cb8c9ff677a0e7b59d8962cdaaeda.file.header.tpl.php on line 147


I also tried to assign that smarty var directly in FrontControllerCore.php (only just to test) but got the same notice.


Any idea?

Luca Reghellin
  • 7,426
  • 12
  • 73
  • 118
  • 1
    UPDATE: I succeeded in get the ovverride recognized, meaning that now I can read this in class_index: 'FrontController' => 'override/classes/controller/FrontController.php', 'FrontControllerCore' => 'classes/controller/FrontController.php', --- That said, I still get the same error when I try to recall a smarty variable in header.tpl Hope someone can help me.. – Luca Reghellin Jul 04 '13 at 16:09
  • 1
    NEW UPDATE: I can see the smarty variable IF I assign it in initHeader() INSTEAD of displayHeader() or init(). Why can't I use that 2 methods? Isn't quite strange? Can someone explain the mechanics of this behaviour? – Luca Reghellin Jul 04 '13 at 16:22
  • 2
    LAST UPDATE: the reason I have to use initHeader instead of displayHeader probably is that displayHeader is deprecated. Using initHeader or initContent is safe. – Luca Reghellin Jul 06 '13 at 09:28

3 Answers3

3

When you create an override you need to recreate the class index.

To do so just remove the file /cache/class_index.php then recreate it (be sure to chmod it to 666 so Prestashop can write it (you can also just remove the content of the file of course).

romainberger
  • 4,563
  • 2
  • 35
  • 51
  • Hi, thank you but it doesn't work. I already tried (and again now). It's really strange to me. Even if I mode directly the core file, empty class_index and all the smarty cache, it doesn't see changes, seems... I instead succesfully created three modules. So... Don't know.. – Luca Reghellin Jul 04 '13 at 14:43
1

Function displayHeader() is not called in Prestashop 1.5 and later versions because it is marked as deprecated. So when you override a not calling function nothing could be happened and you get no results on output.

As I see here the answer from user1145716 is more helpful for your situation and you can override initHeader() function to see results on output.

Mojtaba Rezaeian
  • 8,268
  • 8
  • 31
  • 54
0

be carefull ! in PS1.5 method displayHeader() was deprecated so you have to use initHeader() then it will work, i had same problem.