Cleaning your code using the hook's controller

At this point, your main class, mymodcomments, should be of almost 300 lines. The following section is not a PrestaShop best practice; beware! During the next chapter, I'll use the module with hook controllers.

This is how I chose to split my code to have hook actions in a separate class. You can choose to do it differently (or not at all, in which case, you can skip this section).

Note

I have attached two versions of the module with this chapter:

  • mymodcomments: This is the module you should have now
  • mymodcomments_with_hook_controllers: This is what the module should look like once you add the hook controllers

We will create one controller for each part of our module. For example, in the case of the

Get PrestaShop Module Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.