O'Reilly logo

PrestaShop Module Development by Fabien Serny

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using object models to create cleaner code

At this point, we have a DB request (sometimes almost the same request) in different files of the module: controllers/front/comments, override/classes/Search.php, and mymodcomments.php. So it might be a good time to create the MyModComment object model. Create a directory named classes in your module's directory and place a file named MyModComment.php in it.

Note

The naming convention of PrestaShop is as follows:

  • Set the same name for the file and class
  • Use CamelCase for the name
  • Set the name in singular
  • The name should match the name of the table in the database

Creating the ObjectModel class

First, create your object class (name it as described previously) and extend it from ObjectModel. You will then have ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required