A couple of questions on MVC. Help?

Hello!

Wrote my own mini-framework. So. The site has a choice of currency, will be 2 variables with types (wmr, wmz, wme) and names (rubles, dollars, euros) where the types used in the model, and the title in the visualization. How to properly and where to store?

Another question. There are some parts of the site that are repeated on many pages, and their content is taken from database. Every time a request in the controller? ie to duplicate the code in model and controller? what would you recommend?
July 4th 19 at 23:06
2 answers
July 4th 19 at 23:08
what would you recommend?


1) forget about MVC for a minute. While we're talking about "model". Also is forget about the view, HTML, etc. Only PHP, only hardcore.
2) move all the actions into separate classes, what would you have had to object to the action
3) remove all the duplication in individual objects (that is to specify what is meant by the second item) and remove all dependencies
4) because you have a lot of objects - use the container dependencies
5) to work with the database it makes sense to organize a DAO for example. That is what all that relates to the SQL that would be somehow hidden in them and not spread over all objects. As you can read on the subject Table Data Gateway.

That is, we should form some kind of API. We need news - get the object that knows how to get them. Need something else - this something, too, there is an object able it. How is he going to do it - it is the third.

Further, it is necessary to add a layer that will convert the data returned by the previous API, in the format that we want. It will be the controllers in fact. They need a router, template engine, etc.

In order to eliminate duplication UI-Ki has the sense to distinguish the individual components (e.g. the block with the latest news is a separate UI component). That is, the page will be assembled as though from the pieces.

Well, something like that.
July 4th 19 at 23:10
in the model implement the selection, in the controller call the model and pass it to the template. In the template cycle through the output data

7e0b800fa62a4606afca687518e8a76e.jpeg

Controller for the main page(for example) receives the request, and pulls the widget. Widget pulls database, which returns an array from mysql. This array of models is passed to the widget template. Next, the widget returns to the controller of the main page has already formed the view that the controller of the main page sends to the template.
In the main controller? since the choice of currency is on each page of the website.

And the second question is that? - Henriette.Schumm commented on July 4th 19 at 23:13
: what do you mean in the main controller? Everyone can get your controller. On the second question: implement a widget that is in the model over the sample and renders a template in which you process the result of the model. In the right controller call the widget and pass it to the view you want - Kendrick_Schu commented on July 4th 19 at 23:16
widget should be in the model? - Henriette.Schumm commented on July 4th 19 at 23:19
: the widget has a class(similar to controller), which is called the model of this widget, and there it is passed to the view which then is processed - Kendrick_Schu commented on July 4th 19 at 23:22
: ie get the class widget is the controller which will have the model?

about the currency. There is also a widget have to do? - Henriette.Schumm commented on July 4th 19 at 23:25
: conductive paint - Kendrick_Schu commented on July 4th 19 at 23:28
there is an example of how to make widgets were passed in view of the main page? - Henriette.Schumm commented on July 4th 19 at 23:31
: Just the main, or the layout? - Kendrick_Schu commented on July 4th 19 at 23:34
in the layout - Henriette.Schumm commented on July 4th 19 at 23:37

Find more questions by tags MVCPHP