ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

how to use header and footer in codeigniter

May 31, 2010 8:44am

Subscribe [4]
  • #1 / May 31, 2010 8:44am

    physicfor

    2 posts

    i have site with a dynamic header with diffrent categories
    which changed from page to page i need to include the header in every page
    i create header.php in the view folder but every time
    i have to pass the category array to the header view in every page
    i read the manual and i search this forum there is a similar post with no answer
    please if any one can help
    and here is the very similar post
    http://ellislab.com/forums/viewthread/96974/P0/

  • #2 / May 31, 2010 9:08am

    kkith

    8 posts

    I’m not sure what your question is.

    Hm, the first response by Rey Philip Regis in your link with the similar post has a great example.  Are you asking if there is a way for CI to create a view that automatically includes the category?  If so, then no CI doesn’t do that.  Nor does any other framework I know of.

  • #3 / May 31, 2010 9:17am

    physicfor

    2 posts

    so i think the beast way is to create parent controler with header and footer methods then extend this controler in other controlers
    am i wright !!!!!

  • #4 / May 31, 2010 7:23pm

    vitoco

    400 posts

    i think this may help you to get a different perspective

    http://ellislab.com/forums/viewthread/156134/

    ...maybe a wiki and a working example will help

    Saludos

  • #5 / Jun 01, 2010 8:09am

    physicfor

    2 posts

    i think this may help you to get a different perspective

    http://ellislab.com/forums/viewthread/156134/

    ...maybe a wiki and a working example will help

    Saludos

    thank you
    and for pepole who will read this post i solve my problem with the following
    first i extend the controler class by
    go to libarry in the aplication folder and create MY_Controller.php
    this file contain

    class Application extends Controller 
    {
    
        var $controllers; // These all track root folders for views, models, controllers; specified in Auth config
        var $models;
        var $views;
    
        function header()
        {
        $this->load->view('headerfooter/header');
        }
    
        function footer()
        {
        $this->load->view('headerfooter/footer');
        }
        
        
        function Application()
        {
            parent::Controller();
        }
    }

    then in other controler in my aplication i use

    class Test extends  Application {
    
        //this is the initilization for the class
        function Test()
        {
            parent::Controller();
    
           //parent::Myclass();
        }
        
        function index()
        {
    
            $this->header();
            $this->load->view('test');
            $this->footer();
         }
    
         
                    
    }

    thans every one for helping

  • #6 / Jun 01, 2010 12:22pm

    Piter

    31 posts

    Hi, I use is Layouts:

    application/librares/layout.php

    <?php  
    if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    class Layout
    {
        
        var $obj;
        var $layout;
        
        function __construct($layout = "layouts/page")
        {
            $this->obj =& get_instance();
            $this->layout = $layout;
        }
    
        function setLayout($layout)
        {
          $this->layout = $layout;
        }
        
        function view($view, $data=null, $return=false)
        {
            $loadedData = array();
            $loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);
            
            if($return)
            {
                $output = $this->obj->load->view($this->layout, $loadedData, true);
                return $output;
            }
            else
            {
                $this->obj->load->view($this->layout, $loadedData, false);
            }
        }
    }
    $this->load->library('layout');
    $this->layout->view('myfile', $data);

    Layouts page

    <html>
    <header></header>
    <body>
    <div id="header">
    </div>
    <div id="content">
    <?php echo $content_for_layout; ?>
    <div>
    <div="footer">
    </div>
    </body>
    </html>
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases