2017-04-09 32 views
0

我使用smarty和ci 3.0.6我可以在我的核心中使用基礎控制器嗎?我這樣做,但我不,我認爲沒有任何價值如何在所有視圖中都有變量?

控制器:

class MY_Controller extends CI_Controller { 
public $stats; 
public $title; 

public function __construct() { 

parent::__construct(); 

$this->load->model('User_Model'); 
$var->stats = $this->User_Model->count_Unverified_adviser(); 
$t=$var->stats->Unverified; 
$var->title = 'title'; 
$this->custom_smarty->assign('vars',$var); 
$this->load->vars($var); 

} } 

我的控制器,加載視圖:

class Adviser extends MY_Controller { 
function __construct() 
{ 
    parent::__construct(); 

    $this->load->model('User_Model'); 

} 
public function index() 
{   
    $this->custom_smarty->assign('url',base_url()); 
    $this->custom_smarty->display('test.tpl'); 
} 

我test.tpl:

<td>{$vars.title}</td> 
+0

是否Smarty的顯示錯誤? – m13r

回答

0

您正在給分配函數一個對象。

要以這種方式獲得$vars.title你應該給一個數組:

$this->custom_smarty->assign('vars', array('title' => 'somevalue')); 
相關問題