Welcome Guest, Not a member yet? Register   Sign In
how to use header and footer in codeigniter
#1

[eluser]physicfor[/eluser]
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

[eluser]kkith[/eluser]
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

[eluser]physicfor[/eluser]
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

[eluser]vitoco[/eluser]
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

[eluser]physicfor[/eluser]
[quote author="vitoco" date="1275362597"]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[/quote]

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
Code:
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

Code:
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

[eluser]Piter[/eluser]
Hi, I use is Layouts:

application/librares/layout.php

Code:
<?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);
        }
    }
}
Code:
$this->load->library('layout');
Code:
$this->layout->view('myfile', $data);

Layouts page
Code:
<html>
<header></header>
<body>
<div id="header">
</div>
<div id="content">
&lt;?php echo $content_for_layout; ?&gt;
<div>
<div="footer">
</div>
&lt;/body&gt;
&lt;/html&gt;




Theme © iAndrew 2016 - Forum software by © MyBB