简体   繁体   English

在Codeigniter中使用页眉和页脚的最佳方法

[英]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? 嗨,有人能让我知道在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. 我也在网上浏览,我看到有人在Core控制器中完成了页眉和页脚功能的加载。 Anyone have any idea how to do it? 有人知道该怎么做吗?

Please advise anyone. 请告知任何人。

in your core controller create a method & load your header view & footer view 在核心控制器中创建方法并加载header viewfooter 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 如果您不需要页眉和页脚(例如ajax视图),通常可以调用

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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