SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Template File System

    Hey,
    I am updating my site and one of my friends asked me why i didn't organise all my websites pages into folders to represent the navigation of the site. Example:

    root/parkinfo/ride/index.php

    I said that the reason i didn't do that was because each page used two php includes to "include" the header and footer pages which made the template of the site. I have been wondering about this and now want to organise the site files into folders as i am implementing a breadcrumb script into the site which relies on a folder directory structure. If i do do this then how do i get all the pages to correctly reference the template pages?

  2. #2
    Resident Code Monkey Chris Corbyn's Avatar
    Join Date
    Nov 2005
    Location
    Melbourne, Australia
    Posts
    713
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you looked at using a framework? You baiscally need a front controller, page controllers and view templates. The controllers do all the hard work of locating files etc, but if you use a framework (say Cake, or symfony) then you needn't really think about it, providinded you understand "why" things are done the way they are.

  3. #3
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help. Is there any other simpler ways this could be done as things like Cakephp are confusing me!

  4. #4
    Resident Code Monkey Chris Corbyn's Avatar
    Join Date
    Nov 2005
    Location
    Melbourne, Australia
    Posts
    713
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The best I can suggest is that you read up on MVC (a design pattern). If you read up on the "Front controller" too then you'll probably see examples the same as what you're indicating

  5. #5
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I have just read this:

    http://www.phppatterns.com/docs/desi...roller_and_php

    But I really do not understand it. Can you give me some examples of what I should be using and how it can be put in my site?

  6. #6
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  7. #7
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have three options
    1. Use php.ini to set the include path to the directory holding the templates and then you can just refer to them by name without "../" because php will look in the directory you specified. The path must be the complete path to your include directory ... use phpinfo to get this.
    eg
    include_path = ".:/usr/local/lib/php/pear"
    2. You can use a htaccess file and do
    php_value include_path = ".:/usr/local/lib/php/pear"
    This will fail if you are running PHP as CGI (this elimates most, if not all, shared hosting plans)
    3. The last option is to use the set_include_path option at the top of your script before anything else

  8. #8
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I am going to use the first of your methods Ikeo. Can you explain how I am meant to make the php.ini file and what should I Place in it?

    or

    Could this be done using a .htaccess file? If so then what do I place in there?

  9. #9
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That depends entirely on your hosting. Usually you can't edit php.ini because the host has just one for all the guys on the same shared server.


    However, on 1and1.com and Godaddy.com you're allowed to use a modified php.ini, where you put in the options you want to change in a file, name it php.ini and place it in the root directory of your site.

    Reread my last post to see what to place in your .htaccess file. But if you are running php as CGI as 99% of all shared hosting plans do then you will get a 500 Internal server error.

    So your best shot is probably the 3rd option.

    Quote Originally Posted by rctneil View Post
    Hey,
    I am going to use the first of your methods Ikeo. Can you explain how I am meant to make the php.ini file and what should I Place in it?

    or

    Could this be done using a .htaccess file? If so then what do I place in there?

  10. #10
    SitePoint Wizard rctneil's Avatar
    Join Date
    Jun 2005
    Posts
    1,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    I am testing this on a WAMP installation on my local pc so could you tell me why this is not working? Thsi is at the top of all my pages in php tags?

    set_include_path('C:\wamp\www\template atm upgrade\includes');

    As "www" is the root of the wamp installtion, should i start at "www" instead of "C"?

  11. #11
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that's the right way to do it.
    Can you post your code and the EXACT error you're getting.

  12. #12
    SitePoint Addict dbr's Avatar
    Join Date
    Aug 2006
    Location
    Tucked away in the mountains...
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://us2.php.net/include/
    // Works.
    include 'http://www.example.com/file.php?foo=1&bar=2';

    This is what I did to keep my file structure intact as I started using includes that broke without using the complete path. My site is hosted and I was hoping for a different solution, but rather than throw everything in one directory I added the complete path where needed.

    I currently have a funny little bug occur though: sometimes a page will load fine, and sometimes I have to hit refresh once or twice to get the page to load properly as for some reason it seems the included files are not read. I am using <?php ?> tags.
    Last edited by dbr; Apr 1, 2007 at 07:46. Reason: correct typo
    "Three components make an entrepreneur:
    the person, the idea, and the resources to make it happen."
    Anita Roddick ~British entrepreneur
    dbr founder of: ProximityCast.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •