简体   繁体   中英

Best way to use Header and Footer in Codeigniter

Hi can anyone let me know which is the best way to use the header footer in codeigniter? The way below seems to be troublesome to put into each function to display header footer

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

Also i browse around the web i see some people do the loading of header and footer functions in the Core controller. Anyone have any idea how to do it?

Please advise anyone.

in your core controller create a method & load your header view & footer view

  public function load_view($view, $vars = array()) {
    $this->load->view('header', $vars);
    $this->load->view($view, $vars);
    $this->load->view('footer');
  }

in your controllers, call

$this->load_view('my_view', $view_data);

if you don't need header & footer (for example ajax views), you can normally call

$this->load->view('my_ajax_view', $view_data);

我在github上创建了一个代码库CodeIgniter-Assets来解决Codeigniter的自定义页眉/页脚问题,这很容易配置,希望这能解决您的问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM