so for example a controller that shows blog pages.
in your controller constructor - define the folder your blog view files are in and the template name
// the folder your content files are in
$this->templatefolder = 'blog' ;
// the template name
$this->view_template = 'blog_template' ;
in a method when you are ready to call some views
$data['content01'] = 'search_articles';
$data['content02'] = 'main_article';
$data['content03'] = 'suggested_articles';
$this->load->view( $this->view_template, $data );
the template itself
views/blog_template.php
// opening html etc that is generic to website
$this->load->view('tmpl_open');
// so if the header has to be dynamic
// get the header from a model (or library etc)
// and either pass the header content or just echo it out directly
$this->load->model('header');
if( ! $newHeader = $this->header->returnNewHeader() )
{
// fallback if the header doesn't come back from the model
$this->load->view('default_header');
}
else
{ echo $newHeader ; }
// this is optional but IF the template folder is not set
// we have a default folder called 'pages' to look in for the content views
// but in this example the folder is set to be 'blog'
// so the blog view files will be in application/views/blog/search_articles.php etc etc
if( isset($this->templatefolder)){
$templatefolder = $this->templatefolder . '/' ; }
else { $templatefolder = 'pages/'; }
// header that is specific for the content
$this->load->view($templatefolder . 'header');
// so in this specific example its going to load 3 view files, but this part is completely flexible
if(isset($content01))
$this->load->view($templatefolder.$content01);
if(isset($content02))
$this->load->view($templatefolder.$content02);
if(isset($content03))
$this->load->view($templatefolder.$content03);
if(isset($content04))
$this->load->view($templatefolder.$content04);
if(isset($content05))
$this->load->view($templatefolder.$content05);
if(isset($content06))
$this->load->view($templatefolder.$content06);
if(isset($content07))
$this->load->view($templatefolder.$content07);
if(isset($content08))
$this->load->view($templatefolder.$content08);
// example of an optional file that you can uncomment for testing
// $this->load->view('objecttesting');
// bottom nav bar generic to website
$this->load->view('tmpl_footer');
// closing html etc generic to website
$this->load->view('tmpl_close');
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…