I have a model which returns to controller arrays of user’s information (his posts, information(name,age etc.) and etc). Then I have one view file which has lots of html (tables and etc.) and it represents the user. I need to show the exactly the same user’s profile somewhere else too. Problem is, that before user profile I need to add a few divs. So, is it ok to do like this in one controller:
$this->loadView("HeaderOfParticularPage"); //it contains just divs
$this->loadView("UserProfile", $user); //$user is array of arrays of information of user
$this->loadView("SomeOtherInfoINeedForFooter");
Is it ok? Or it’s bad practise? Thanks.
It’s perfectly acceptable to modularize and reuse views like that, since each serves a different purpose of its own. MVC web apps aren’t restricted to a single view (or a single controller, or a single model) per page.
You could even say that what you’re doing is the “MVC version” of server-side includes.