Codeigniter包含在视图中

New to CI so please excuse if this is an offensively straight forward fix.

I have a number of views where I need to be able to include the same piece of navigation like so:

...
<div class="projectNav">
  <?php 
    echo anchor('projects/view/' . $project->intId, '<img src="'.base_url().'assets/img/icons/zoom.png" />'); 
    echo anchor('tasks?project=' . $project->intId . '&status=open', '<img src="'.base_url().'assets/img/icons/puzzle.png" />');
    echo anchor('projects/edit/' . $project->intId, '<img src="'.base_url().'assets/img/icons/edit.png" />');
    echo anchor('projects/charges/' . $project->intId, '<img src="'.base_url().'assets/img/icons/sterling_pound_currency_sign.png" />');
  ?>
</div>
...

Obviously, as it is standard across each of the views, I don't want to repeat myself. What is the best practice way to do "include" this nav with CI?

$this->load->view('nav');

Will load nav.php in your views folder inside Application. This method can be run from a controller or view.

You can do it in two way (as per my knowledge)

in controller (if you are including in controller you should load in same sequence the way you want to see.)

$this->load->view('nav')

In View

include('nav.php')

Looks like you are looking for a template/layout system. One implementation for CodeIgniter can be found at http://daylerees.com/layout/.

If you don't want to use a full layout engine, you can add a display_override hook to manipulate your view. This is briefly described at http://maestric.com/doc/php/codeigniter_compress_html.