Is it bad to use a model directly from a view in a codegame?

I know that usually data is transmitted through a view with a controller. however, currently, in my opinion, I am loading my model ($ this-> load-> model ('Db_model');), so I can use it in a loop to retrieve the user profile image path from the identifier array that is passed from the controller. Will loading the db model in the view for this make my site more vulnerable or poor? For me, this seems to be outside the concept of MVC, but its working atm. thanks

+4
source share
3 answers

I agree, but it has everything related to the scale. If you are developing a tiny MVC application, it does not really matter, because it is easy to control the entire application. However, as soon as the application starts to grow, or if you create a larger application, MVC separation becomes more important.

For example, if you use models in your views, this means that the development team must know about the models. It may also prevent the transfer of views later to another structure or template replacement.

+5
source

Well, if you do something outside of MVC, this does not mean that it will stop working in that second. MVC is just a design template that should help you develop and maintain your site. The basic principle is that the model should only communicate with the controller and view only with the controller, so your idea of ​​invoking the model directly from the view is not MVC's way of doing things.

If you need additional data from the model, why not get it in the controller and pass it as another parameter for the view so that it can easily use it? There will probably be the same code and your code will be much cleaner. Keeping your code clean may not seem so big if you remember where everything is stored, but after a few months when you forgot some of these things, you may run into a headache if you damage the application too much.

+3
source

Look at the libraries. You should consider creating a helper library class to display the profile image. Then you can call the library call. Then, in your opinion, you simply do:

<?php $this->profile_helper->display_picture(); ?>

where profile_helper is your library class, and display_picture () is your class function to display the user profile.

0
source

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


All Articles