如何在codeigniter的每个页面上运行一个函数

如何在codeigniter的每个页面上运行一个函数

问题描述:

我正在基于codeigniter制作一个站点。我的索引页中有一个页眉和页脚。如何在codeigniter的每个页面上运行一个函数

这里是我的控制器:

<?php 
    defined('BASEPATH') OR exit('No direct script access allowed'); 

    class Travels extends CI_Controller { 

     function __construct(){ 
      parent :: __construct(); 
      $this->load->model('travel'); 
     } 

     public function index() 
     { 
    $data= array(
       'menu_products'=>$this->travel->menu_products(); 
       'footer_products'=>$this->travel->footer_products(); 
    ); 
       $this->load->view('index', $data); 

     } 
    } 
    ?> 

这是在索引页上工作正常,但我想每个页面上的页眉和页脚。正如你所看到的,我正在加载索引页面的视图。我怎样才能在每一页上获得页眉和页脚???请帮助我。

使用此项

$this->load->view('header'); 
$this->load->view('content'); 
$this->load->view('footer');