Page 1 of 1

include advice

Posted: Thu May 22, 2008 11:49 am
by mrgooding
Hi all

I've done a bit of research on this, but couldn't find anything definitive. I've started constructing a website, with two separate pages that I include at the top of most of my .php pages - one is for authentication, the other is my database connection function.

Do I need to ensure each page includes the two files, or does including them on an index page which links to others allow them to cascade, so to speak?

Re: include advice

Posted: Thu May 22, 2008 12:01 pm
by pickle
No - you need to include them at the top of each page. When viewing a page, the web server has no idea what other pages you've viewed in the past - so you need to make each page function fully on its own.

Re: include advice

Posted: Thu May 22, 2008 12:37 pm
by JAB Creations
I have an extensive includes template setup.

First I have the parent templates which include child templates.

If you request a file such as main.php it will include only parent templates (and a single different type of template where the unique page's content is pulled from).

When you look at the parent templates they include the child template files. On my site I allow lots of various cookie based tweaks such as choosing a DTD, media type, CSS themes, initial keyboard focus, etc. So to keep everything organized I have a numerical top to bottom numbering system. To give you an idea it sort of looks like this...

template-child-01-xml.php
template-child-02-dtd.php
template-child-03-doctype.php
template-child-04-css.php
template-child-05-javascript.php
template-child-06-body.php
template-child-07-sidebar-00.php
template-child-07-sidebar-01-search.php
template-child-07-sidebar-02-signin.php
template-child-07-sidebar-03-tools.php
template-child-08-menu-01.php
template-child-09-menu-02.php


When I first started using this form of organization it only took me a couple of months to finally settle on the final naming scheme though it is vastly easy for me to figure out what file I need to look at even if I don't have the exact name in my head. You'll notice the first child 07 sidebar which is like a third level includes. So the includes order from the requested file to the search would be main.php --> parent parent --> template-child-07-sidebar-00.php --> template-child-07-sidebar-01-search.php.

Of course this might not work for everyone nor for all situations though it's an option you can keep in mind if you find it may better serve a future project you choose to pursue. Have fun! :mrgreen: