In this blog, we are going to learn the PrestaShop controller lifecycle to ease the module development and work PrestaShop uses predefined steps in controller execution one by one.
Here we are going to explain to you the hierarchy of controller method execution.

In below example, you can find step-by-step methods called in the controller
The execution order of the controller’s functions : classes/controller/Controller.php
I. __construct() II. run() (called by Dispatcher->dispatch) 1. checkAccess() 2. init() A. AdminController->init(): i. check employee ii. $this->initProcess(); a. if $_POST filter, $this->filter = true b. Define $this->action based on different conditions c. $this->action = delete_image/delete/status/position/ save/new/view/details/export/ reset_filters/update_fields/bulk d. can error You do not have permission to view/edit/add/delete iii. $this->initBreadcrumbs(); iv. $this->initModal(); v. $this->initToolbarFlags(); a. $this->getLanguages b. $this->initToolbar c. $this->initTabModuleList d. $this->initPageHeaderToolbar $this->loadObject [in 'view' or 'edit'] can error The object cannot be loaded (or found) or The object cannot be loaded (the identifier is missing or invalid) vi. $this->initNotifications(); B. FrontController->init() i. // To do 3. setMedia() or setMobileMedia() Adds all JavaScript and CSS specifics to the page so that they can be combined, compressed and cached 4. AdminController->setMedia() A. $this->addCSS(themes, css, public, vendor) B. $this->addJS(themes, css, public, vendor, public bundle) 5. postProcess() A. AdminController->postProcess() i. $this->processFilter() [if !$this->ajax && $this->filter] ii. Hook actionAdmin{Action}Before iii. Hook action{Class}{Action}Before iv. process{Action} (or ajaxProcess{Action} if $this->ajax) v. Hook actionAdmin{Action}After vi. Hook action{Class}{Action}After B. FrontController->postProcess() 6. redirect() [if $this->redirect_after] 7. initHeader() 8. initContent() A. AdminController->initContent i. $this->viewAccess ii. $this->loadObject(true) iii. [if display == edit/add] a. loadObject(true) b. renderForm iv. [if display == view] a. loadObject(true) b. renderView v. [if display == details] a. renderDetails vi. elseif !$this->ajax a. $this->renderModulesList() b. $this->renderKpis() c. $this->renderList() d. $this->renderOptions() e. $this->displayRequiredFields [if $this->required_database] vii. assign 'content' B. FrontController->initContent // todo 9. initFooter() 10. displayAjax() [if $this->ajax] 11. display() [else] A. FrontController->smartyOutputContent B. AdminController->smartyOutputContent($this->layout)
This is how controller methods are executed in PrestaShop in top-to-bottom order when a controller is called. You can easily understand and start your development with the help of the above details.
In a MVC architecture, a Controller manages the synchronization events between the View and the Model, and keeps them up to date. It receives all the user events and triggers the actions to perform.
If you are looking for function uses in the above example you can visit the given links.
That’s all.
If you are facing any issues or doubts in the above process, please feel free to contact us in the comment section.
I would be happy to help.
Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.
For any doubt contact us at [email protected].
Be the first to comment.