bujashaka Posted May 24, 2014 Share Posted May 24, 2014 Hello. I'm in need of help when it comes to page rendering, is it good practice to have own html file for each controller and controller->method OR 1 view file for each controller and then dynamically change content depending on the method? My structure is like so: controllers methods ------------- services-> repair, car glass..... info-> contact, about me..... What is the best or good practice to handle the content in the view? The content is always the same. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/288731-php-mvc-coding-style-advise-needed/ Share on other sites More sharing options...
Frank_b Posted May 24, 2014 Share Posted May 24, 2014 It depends on the situation. I render pages using multiple controllers and multiple views. For example if you want to place a list in a sidebar of -by example- the last 10 posts of your blog over a number of pages it would be stupid to copy and past that code to every page that need to be rendered. In such a situation its better to make a new controller and a new view. That view wont render more then a html list (<ul>) within a container div. Some frameworks give not much posibilities to call another controller from the main-view but the better ones do. I use Symfony. Quote Link to comment https://forums.phpfreaks.com/topic/288731-php-mvc-coding-style-advise-needed/#findComment-1480684 Share on other sites More sharing options...
requinix Posted May 24, 2014 Share Posted May 24, 2014 As long as you're separating the logic (controller) from the HTML (view, or at least most of the view), you're following the principles of MVC. Beyond that is debatable. Realistically, one file for all the views would be hectic and a hassle to manage. Want to change the "about me" page? You'll be ignoring a lot of stuff in the file because it corresponds to different pages. Go with one file per view/method. Quote Link to comment https://forums.phpfreaks.com/topic/288731-php-mvc-coding-style-advise-needed/#findComment-1480687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.