Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Auto include on index.php only working on home

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #149849

    Hi I am trying to get it so any file that is ending in .tpl will have header and footer added. So far can only get one home page

    <?php 
       $path = $_SERVER['DOCUMENT_ROOT'];
       $path .= "/template/common/header.tpl";
       $path .= ".tpl";
       include_once($path);
    ?>
    
    #149902
    __
    Participant

    Hi I am trying to get it so any file that is ending in .tpl will have header and footer added. So far can only get one home page

    I don’t follow. In your example above, $path would contain “{path-to-your-document-root}/template/common/header.tpl.tpl“. That doesn’t sound like what you’re describing.

    If you want your templates to have a shared header + footer, just add them to the template:

    <?php
        include( 'header.tpl' );
    
        <p>This is my page template</p>
    
        include('footer.tpl');
    
    #149922

    I have been google today found out to be able to do what I am after I need A MVC template engine would you know a easy one I had look in to smarty php but need something easy to learn off.

    #150007
    __
    Participant

    I have been google today found out to be able to do what I am after I need A MVC template engine

    Instead of just jumping to conclusions, you should research what “MVC” means – your templates are only the “V” (“View”) part.

    While I do recommend learning about and following MVC patterns, you do not need to change your entire approach simply to include a shared header and footer on your pages.

    Also, while I don’t really like Smarty, it is suited for use in an MVC structure.

    #150017
    Alen
    Participant

    Overview of MVC Design: http://youtu.be/qXRcVhWxuaU

    Some PHP frameworks that implement MVC.

    • Laravel
    • CodeIgniter
    • CakePHP
    • Symfony
    • Zend Framework
    • Yii
    • FuelPHP
    • Kohana

    I like Laravel. And if you’re interested in learning more about the framework, Jeffrey Way is working on a site that will take you from novice to pro for very low monthly price. http://laracasts.com & http://laracasts.com/forum/

    Although, like @traq said you should really figure out what you’re after then seek the “right” solution. You might not need framework. Or the MVC design pattern.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘Back End’ is closed to new topics and replies.