Jump to content

Create a front controller


beginner1
 Share

Recommended Posts

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 by GoFenice (see edit history)
  • Thanks 2

Share this post


Link to post
Share on other sites

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');
	}
}

 

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More