Welcome Guest, Not a member yet? Register   Sign In
Application Constants (header, footer)
#1

[eluser]x_dde_x[/eluser]
Still trying to figure Codeigniter out... In my previous sites, I've always constructed around not re-writing header and footer information on each view. For example, I would render the page thusly from the index call:
Code:
include('header');
include('PAGE_URL');
include('footer');

And all meta data and css links would be appended, and the page would be constructed.

Does CodeIgniter have a similar mechanism, or do you have to load other views in each individual view file?
#2

[eluser]Rey Philip Regis[/eluser]
Yup Ive discussed that before try to visit this link: I think you and khuram have the same problem..There I discussed a technique that you can use without having to include you header and footer on every view. You just need a template. What I do there is loading a view within a view. You'll start on creating a master template and in that template you need to load your header and footer just once and the content will allso be loaded but its loaded dynamically by setting them in your controller. This is what we call Two step view pattern, I think haha..

Try to view this:

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

Hope this helps..
#3

[eluser]got 2 doodle[/eluser]
I started to work in a very modular way.

In controller define all the data .. building an array called 'data'
Code:
..in a function ..
$page_name = 'programs';
    $this->load->model('pagedefault');
    $data = $this->pagedefault->get_default($page_name);
    $this->load->model('program_data');
    $data ['programs'] = $this->program_data->get_program_dropdown_array();
    $data ['themes'] = $this->program_data->get_theme_dropdown_array();
    $data ['dates'] = $this->program_data->get_date_dropdown_array();
    $data ['feature'] = $this->program_data->get_featured_program_data();
    $data ['count_year'] = $this->program_data->get_program_count_by_year($theYear);
......etc...

define your views note that we are setting $output as the view content and then appending to this var.
note the parameter 'true' this keeps appending and also note that you only have to send your data array in the when you first define the output.
Code:
/* Load views  */
    $output = $this->header_view($data);
/* Load the left hand column */        
    $output .= $this->load->view('view_left_col_open',"",true);
    $output .= $this->load->view('view_nav',"",true);
    $output .= $this->load->view("$page_name/ls_content","",true);
    $output .= $this->load->view('view_col_close',"",true);
/* Load the center column */                
    $output .= $this->load->view('view_center_col_open',"",true);
    $output .= $this->load->view("$page_name/view_content","",true);
    $output .= $this->load->view('view_col_close',"",true);

note I grouped view chunks together as in
Code:
function header_view ($data)
    {
    /* Load the header and banner */
    $output = $this->load->view('view_header',$data,true);
        $output .= $this->load->view('view_banner',"",true);
    /* open the main container */        
        $output .= $this->load->view('view_container_open',"",true);
        //$output .= $this->load->view('thumb',"",true);
        return ($output);
    }
here is the footer
Code:
function footer_view ($output)
    {
    $output .= $this->load->view('view_col_close',"",true);
    /* close the main container */
        $output .= $this->load->view('view_col_close',"",true);
    /* Load the footer content */        
        $output .= $this->load->view('view_footer_open',"",true);
        $output .= $this->load->view('view_bottom_nav',"",true);
        $output .= $this->load->view('view_footer',"",true);
/* Done loading views */        
        $this->output->set_output($output);
    }
this line
Code:
$this->output->set_output($output);
has to be the last line

anyway, I doubt anyone else works exactly like me but for the project this approach worked.

adamp had a nice approach with backendpro, a page class and an asset management class

To get the views looking how I want, I start my layout work in Dreamweaver and then take it all apart in logical chunks.
Wink doodle
#4

[eluser]x_dde_x[/eluser]
[quote author="Rey Philip Regis" date="1228261910"]Yup Ive discussed that before try to visit this link: I think you and khuram have the same problem..There I discussed a technique that you can use without having to include you header and footer on every view. You just need a template. What I do there is loading a view within a view. You'll start on creating a master template and in that template you need to load your header and footer just once and the content will allso be loaded but its loaded dynamically by setting them in your controller. This is what we call Two step view pattern, I think haha..

Try to view this:

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

Hope this helps..[/quote]

Awesome, this helped quite a bit. I built the template page and am off to the races!
#5

[eluser]Rey Philip Regis[/eluser]
Your welcome.. Happy coding..
#6

[eluser]Michael Wales[/eluser]
I like to just do something simple like this:

controllers/posts.php
Code:
function index() {
    $this->data->partial = 'posts/list';
    $this->load->view('layout', $this->data);
  }
}

views/layout.php
Code:
$this->load->view('_header');
$this->load->view($partial);
$this->load->view('_footer');

If my headers/footers/sidebars etc. are going to contain dynamically generated content, I usually use Zacharias' awesome Wick library.
#7

[eluser]Rey Philip Regis[/eluser]
That's a nice library Michael..




Theme © iAndrew 2016 - Forum software by © MyBB