How To Implement a Controller In a Custom Module

Dec 11, 20121646
How To Implement a Controller In a Custom Module

Prestashop 1.5.x has treated us with a wonderful possibility to implement controllers in modules. This is the main goal of ModuleFrontController and ModuleAdminController classes. Let’s take a closer look at them (pay attention to comments):

Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor


Let’s now pass from theory to practice. For Prestashop to call Frontend controller right from the module folder, it’s necessary to create the controllers/front/mycontroller.php file in the module root directory.

Templates of your module can be located either in the root directory or here:


Modulecontroller URL differs from front-end controllers and looks like this:

Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor


  1. very interesting.

    How may I call a controller method as I used to do with


    in version 1.4 ?

  2. Thanks for your help.

    I would like to call a controller method.
    So, do you know how to instaciate a controller with presta 1.5 ?
    In presta 1.4 I used ControllerFactory::getController(‘
    but it seems to work no more.

  3. Ademus,

    Try the following method:

    In a controller class:

  4. Hi there..

    I got a simple problem here but really need a solution.
    I made a module that can change colors for shop theme. it is functioning.

    Then i added an iframe in the admin form (form.tpl) so that anything change you may see the results instantly without have to click ‘view my shop’.

    so for the iframe, i use smarty variable {$base_dir} for it’s src.

    it ends up with sowing nothing. Debugging the actual site, the iframe element have blank on the src value.

    And the question is, in the form.tpl, what is the right method to call any smarty variable? It seems that in the form.tpl doesn’t recognize the smarty variable. I thought that should be global ?

  5. Dudy,

    To output errors instead of a blank screen you need to follow recommendations described in this article.

    All the rest you are doing right, in any smarty template it is possible to use variables such as {$var}.

  6. Great explanation as usual, I work at PrestaShop but I still learn things on your website :)

    I would just add one useful piece of info: You can get the URL to this controller with the Link class like this:

    $this->context->link->getModuleLink(‘module_name’, ‘controller name’);

    This works from all objects that have a context: modules, other controllers, etc.

  7. Hi, excuse me for send you message for this form. I have a problem on creation the module on dashboard in my prestashop site. I need call a function of mymodule.php from an archive .tpl but only when I press function onclick the button. I think that you could help me. Thanks.

  8. Hello

    Can you please send me code for creating controller in admin folder of module by extending ModuleAdminController . I tried different ways but every time I get an error “Controller not found”.


Post a new comment

BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *