Jump to content

PHP MVC coding style advise needed


bujashaka

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.