論詞,你必須直接從你的控制器的構造函數加載一個視圖的可能性的結尾來看,我加載我的網頁的頁眉和頁腳(因爲它是每個相同功能)代碼點火器裝在控制器
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
}
}
但是,這將裝載的裝載我的函數前頁腳視圖,那麼,有沒有辦法做到這一點沒有「手動」裝載每個函數結束的看法?
您可以使用[鉤](http://codeigniter.com/user_guide/general/hooks.html)之前加載頭你的控制器函數(post_controller_constructor)和之後的腳註(post_controller)。 –
@Rocket不能也使用'__destruct()'方法嗎?或者我有這個錯誤的概念? – gorelative
使用** **掛鉤是一種創造性的方法,但它可能會很麻煩,如果你不希望頁眉/頁腳做時間的100%。 –