开发者

codeigniter sidebar

i have a little problem that i dont know what to do with.

i have a template with

  • header
  • content
  • sidebar
  • footer

on all my page the only thing that need to change is the content, so how can i pass data 开发者_如何转开发to my sidebar/footer

do i need to make a controller? or do i need to make a library and load it in my template.php file?

i use this template system http://williamsconcepts.com/ci/codeigniter/libraries/template/index.html


I am not sure about your specific Template Library, but I do know that generally this is done by nesting views inside other views, and as long as the data is loaded into the initial view, it propagates to nested views as well.

Example without Template library

Controller function

function index() {

    $data['some_var']    = "some value";
    $data['another_var'] = "another value";

    $this->load->view('first_view',$data);
}

first_view

<? $this->load->view('header') ?>

<h1>Content</h1>

<? $this->load->view('sidebar') ?>
<? $this->load->view('footer') ?>

In this instance, the $data that is loaded into first_view propagates to header,sidebar,and footer.

So you can use $some_var or $another_var in any of these views.

UPDATE

Another way you can load data in to your views globally is with this function

$this->load-vars($data); 

Where $data is your view data, this statement just before you load your template should allow all of this data to be accessed in any view loaded by the template. While this is a shotgun approach, it is the suggested way to do this by your chosen template library.


If you will only ever change content, then there is no need to set up regions for your header, sidebar or footer - just add their contents to your main template file.

However if you will infrequently need to change the content of these regions, I would create "default" views for these regions, and load in each controller constructor, like thus:

$this->template->write_view('header', 'default/header');
$this->template->write_view('sidebar', 'default/sidebar');
$this->template->write_view('footer', 'default/footer');

You can then either extend these default region views or overwrite them on a per method basis (refer to the documentation of your library to find out how).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜