beginner1 Posted October 26, 2017 Share Posted October 26, 2017 (edited) Hi I am a beginner in prestashop and I want to create a front controller for the in prestashop. How can I achieve that? Edited October 26, 2017 by beginner1 (see edit history) Link to comment Share on other sites More sharing options...
GoFenice Posted October 27, 2017 Share Posted October 27, 2017 (edited) you have two ways to creating a custom front controller 1. using override simple create a controller in override/controllers/front/YourController.php for references you can check the core controllers in controllers/front/ after creating the controller you have to delete the file cache/class_index.php - this to be done to detect your newly created controller file 2. create a module front controller create your own module and a module front controller modules/yourmodule/controllers/front/custom.php <?php class YourmoduleCustomModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent() $this->setTemplate('my-template.tpl'); } public function setMedia() { parent::setMedia(); $this->addJS('your-js-path'); } } here the template file should be yourmodule/views/templates/front/my-template.tpl and you can use the setMedia method only if you have custom js or css files to be loaded for your specific page, if not please remove it. and you can access this page using this url when friendly url is enabled - yourdomain/module/yourmodule/custom when friendly url is off - yourdomain/index.php?controller=fc&module=yourmodule&fc=custom Thanks, Edited October 27, 2017 by GoFenice (see edit history) 2 Link to comment Share on other sites More sharing options...
catalin.pop Posted October 31, 2017 Share Posted October 31, 2017 Google can be your friend: https://belvg.com/blog/prestashop-1-7-mvc-part-2-creating-a-controller.html class mymoduleMycontrollerModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $this->context->smarty->assign(array( 'hello' => 'Hello World!!!', )); $this->setTemplate('template_name.tpl'); } } Link to comment Share on other sites More sharing options...
bellini13 Posted October 31, 2017 Share Posted October 31, 2017 You could also read the developer guide in the More menu of their website. You could also review existing front controllers (there are 30 of them included in the core of prestashop) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now