in native templating / mvc who should load includes?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

in native templating / mvc who should load includes?

Post by alvinphp »

In a native templating mvc type architecture is it better to have

1. my controller load header.php, mypage.php, and footer.php

OR

2. my controller load mypage.php and that page loads my header and footer include pages?

OR

3. I am just being anal.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

I am thinking 1 is the best method as it best seperates business logic with the presentation layer.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm thinking number 0.

Front Controller can load in header and footer, as well as the correct page controller. The page controller can then load in mypage.php.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

d11wtq wrote:I'm thinking number 0.

Front Controller can load in header and footer, as well as the correct page controller. The page controller can then load in mypage.php.
Not using a front controller and do not want to in my particular situation. So, I would say you are more with 1 where the controller loads the include pages. Thanks!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

alvinphp wrote:So, I would say you are more with 1 where the controller loads the include pages. Thanks!
Yes, I sway toward 1 ;) If the header and footer are the same on each page (with maybe the exception of a button highlighted on a per-page basis) I would consider refactoring a little to centralize the loading of the header and footer however ;)
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Actually number 2 would be the better way to go. This will allow you to have DIFFERENT headers and footers. It will allow far more control over what is being displayed.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

d11wtq wrote:
alvinphp wrote:So, I would say you are more with 1 where the controller loads the include pages. Thanks!
Yes, I sway toward 1 ;) If the header and footer are the same on each page (with maybe the exception of a button highlighted on a per-page basis) I would consider refactoring a little to centralize the loading of the header and footer however ;)
This is assuming every page/module uses the same header/footer. Granted, you can have the controller decide what header to use (if at all). Do not get me wrong, I love the front controller pattern and use it quite extensively already.
Last edited by alvinphp on Wed Aug 23, 2006 6:50 pm, edited 2 times in total.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

AKA Panama Jack wrote:Actually number 2 would be the better way to go. This will allow you to have DIFFERENT headers and footers. It will allow far more control over what is being displayed.
That is true, plus some includes might have to be integrated inside a main page where you need to add the include inside mypage.php versus a header/footer which goes on the top/bottom of the page and is easy for a controller to handle. Hmmm, maybe I will stick with 2. I would like includes to all happen in the same place as it makes it easier for me to work with the code.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If you are using a template engine ala Smarty, it would be the template that loads the header/footer and if there is any specific logic for it, the controller for that template would load the logic (as well as the template include the template for it)
Post Reply