在 Ci 上,您可以直接从 Controller 的构造函数加载 View ,我正在加载页面的页眉和页脚(因为每个函数都是相同的)
class Add extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->view('header_view');
$this->load->view('footer_view');
}
function whatever()
{
//do stuff
}
}
但这会在加载我的函数之前加载页脚 View ,所以有什么方法可以在不“手动”加载每个函数末尾的 View 的情况下做到这一点?
最佳答案
我会在主视图中添加带有数据的页眉/页脚,或者使用模板库(我使用这个 one )。
如果在功能主视图中;
// in view for html page
<?php $this->load->view('header'); ?>
<h1>My Page</h1>
<?php $this->load->view('footer'); ?>
关于php - codeigniter 在 Controller 末尾加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998293/