Connecting to a Database in the Zend View Helper

Is it good practice to use databases in the Zend View Helper? Because in my case, this helper makes me a <div> box, which continues to change in real time and should be displayed in all the views that are in my application. I cannot let this object load it from the database in the controllers and assign it to view it every time.

It would be very helpful if someone could say good programming methods that should be followed when working with helpers of the zend type, for example:

  • If it’s ok to assign something to the view in the view helpers with $this->view->variable = ... ;
  • If everything is in order to create and use models in View Helpers.
  • If this is normal, use the methods available by Zend_View inside the view helper, for example by doing $this->view->baseUrl('...');
+4
source share
1 answer

Your second and third bullet seems right to me if you are not doing any logical things in your model from your ideas. The relationship between models and views should be read-only.

As for your first point, you don’t need to assign anything to the view, you see that the helper should return to output the HTML code directly to the view.

In your first question, you can create a View Helper that specializes in this task, so you can use it as a simple proxy between your helpers and map makers. One view helper will allow you to access any map maker, while others will help people who can use this view helper to get a mapping.

See what Trygwe Reyenkaug thinks about MVC:

Models

Models are knowledge. A model may be a single object (rather uninteresting), or it may be some structure of objects.

There must be a one-to-one correspondence between the model and her on the one hand, and the presented world, the perceived owner of the model, on the other hand.

Views

A view is a (visual) representation of its model. This is usually highlighted by certain attributes of the model and suppressed by others. Thus, it acts as a view filter.

A presentation is attached to its model (or part of the model) and receives the data necessary for presentation from the model, asking questions. It can also update the model by sending appropriate messages. All these questions and messages should be in the terminology of the model, so the view must know the semantics of the attributes of the model that it represents.

Controllers

The controller is the connection between the user and the system. This is provided by the user with tabs, organizing the corresponding views for presentation themselves in the appropriate places on the screen. It provides facilities for user output, introducing the user with menus or other ways of providing commands and data. The controller receives such user output, translates it into appropriate messages, and transmits these messages to one or more views.

+2
source

Source: https://habr.com/ru/post/1398805/


All Articles