CodeIgniter Forums
PHP Includes within Directories - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: PHP Includes within Directories (/showthread.php?tid=6071)



PHP Includes within Directories - El Forum - 02-13-2008

[eluser]pgsjoe[/eluser]
I never truly know whether or not I'm doing things the correct way. This is more of a general PHP question, but with regard to CI. I use a head.php and a foot.php on the majority of my files. I feed in other variables as well such as mainNav.php, etc. I've run into a real problem when I begin to put items into directories. For instance, if I have

/head.php
/index.php
/foot.php
/about/bios.php

How would I want to include the head and foot file within there? I've tried using a config file so that my includes are as follows:

include ($root . 'head.php'); But what should root be? I tried using $_SERVER['DOCUMENT_ROOT'] but that brings me back too far and it's like /home/web1/www/domain.com

With relation to CI, I have CI in my root directory. In there, I want to reference the same head elements, but each item is buried 2 or three deep. Do I really have to resort to ../././ for each include? Thanks in advance.


PHP Includes within Directories - El Forum - 02-13-2008

[eluser]Sean Murphy[/eluser]
Why not use something like
Code:
$this->load->view('includes/header.php');

That way all the paths are relative to the views directory.


PHP Includes within Directories - El Forum - 02-13-2008

[eluser]pgsjoe[/eluser]
I'm not fully using CI to handle the entire site yet, just bits and pieces right now.