Book Image

PrestaShop Module Development

By : Fabien Serny
Book Image

PrestaShop Module Development

By: Fabien Serny

Overview of this book

Table of Contents (19 chapters)
PrestaShop Module Development
About the Author
About the Reviewers

Using front controllers to create a new page

If you need to create a complex module, you will need to use front controllers. First of all, using front controllers will permit to split the code in several classes (and files) instead of coding all your module actions in the same class. Also, unlike hooks (that handle some of the display in the existing PrestaShop pages), it will allow you to create new pages.

Creating the front controller

To make this section easier to understand, we will make an improvement on our current module. Instead of displaying all of the comments (there can be many), we will only display the last three comments and a link that redirects to a page containing all the comments of the product.

First of all, we will add a limit to the Db request in the assignProductTabContent method of your module class that retrieves the comments on the product page:

$comments = Db::getInstance()->executeS('
  SELECT * FROM `'._DB_PREFIX_.'mymod_comment`
  WHERE `id_product` = '.(int)...