Good day! I asked two questions on the implementation of certain functions. I can not decide how to create them correctly - as a component, or as a widget, or as a separate class. More details below.


  1. How best to create additional support functions that can be used in different controllers?

Example:

We have an alert() function that is responsible for recording alerts (writing to the database for later output) about some events that may be in different controllers (k) / models (m). For example: a new user has registered (K: UserController, M: User), a comment has been left in the blog (K: BlogController, M: Article).

How best to implement this? In the form of a component? Or just create any independent separate class?


  1. How best to implement the output of meta-data, the connection of third-party modules?

Example:

Suppose we have 2 tables in the database: 1 - with which we need to output meta-data for certain actions. 2 - with which you need to display third-party scripts (for example, jivo-chat, metrics, etc.) that the user manages in the control panel.

How best to implement? In essence, widgets are used for the HTML presentation, right?

    1 answer 1

    All project logic must be executed either in models or in functional classes. Therefore, both of your points will be the most efficient in the component, it is autonomous, access to it can be obtained from any part of your project, it has its own logic and, if necessary, its own idea. Widgets are reusable building blocks, i.e. some html code that you use reusable for the entire project. Therefore, for example, the same metadata can be implemented using the widget for each page of your site.