Jump to content

Override FrontController.php


Recommended Posts

Hi everybody!

 

I have a simple question: I need to create a PHP variable and add it on the template (for example: a class on the body in header.tpl).

 

I have found this article, and I have followed:

https://stackoverflow.com/questions/32154593/create-variable-accessible-through-all-templates-in-prestashop/32247800

 

I'm newbie in prestashop, so I am not sure if that is the rigth way; but anyway it doesn't work for me.

I have read also: http://doc.prestashop.com/display/PS16/Overriding+default+behaviors

 

If I write my variable in classes/controller/FrontController.php (a simple: $this->context->smarty->assign('myvar', 'something'); ) it works, but if I write the same in override/classes/controller/FrontController.php , it doesn't work, so prestashop doesn't read my override.

 

I have tried inside of "public function init()" and also in "public function initHeader()", but not way.

If you have any idea I will appreciate your comments.

Thanks a lots!

Link to comment
Share on other sites

Hi...

Best way is override Like as above "override/classes/controller/FrontController.php"
 

class FrontController extends FrontControllerCore {
public function initHeader(){
//create your variable
self::$smarty->assign('yourVariable', 'valueOfYourVariable');

//call original method, to maintain default behaviour:
return parent::initHeader();
}
}

Then after
 

go to cache directory (from shop root) and delete file called "class_index.php" no worries its auto generate
 
clear the "cache" in your prestashop back office->Advanced Parameters > Performance.

Thanks
Link to comment
Share on other sites

Thanks Nishth for your reply.

Yes, that is exact what I did it, but it doesn't work.

I don't know why :(

 

I wanted to give to you the link to the page, but now is in maintenance mode.

I know, in the normal process it has to work properly; so is difficult to find the problem.

I dont' know what more try.

Anyway, thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...