2012-11-26 45 views
0

如何將變量從控制器傳遞給構造函數?將變量從控制器傳遞給codeigniter中的構造函數

function __construct() 
{ 

    parent::__construct(); 

    $info['title'] = 'No title'; 
    $this->load->view('include/header',$info); 
} 


function be_cool() 
{ 

    $info['body'] = 'template/becool'; 
    $info['title'] = 'This is the be cool title'; 

    $this->load->view('include/template',$info); 
} 

function be_hot() 
{ 

    $info['body'] = 'template/behot'; 
    $info['title'] = 'This is the be hot title'; 

    $this->load->view('include/template',$info); 
} 

即時嘗試根據控制器中定義的值更改標題。但它似乎並沒有工作。任何想法我做錯了什麼?

回答

0

您有語法錯誤。在您的be_cool()方法:

$$his->load->view('include/template',$info); 

應該

$this->load->view('include/template',$info); 

而且還$his應該$this在你的另一種方法。

+0

我修正了這些錯誤,但我仍然無法將標題值傳遞給構造函數.. – LiveEn

+0

哦。您正在將標題加載到包含/模板視圖中,但我懷疑您希望它們位於標題中。請不要每次加載標題視圖,請查看一些模板庫。它可以節省大量的時間:https://github.com/philsturgeon/codeigniter-template – nielsiano

相關問題