Php 如何在所有视图中使用变量?

Php 如何在所有视图中使用变量?,php,codeigniter-3,smarty3,Php,Codeigniter 3,Smarty3,我使用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 = $thi

我使用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');  
}
my test.tpl:

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

您正在为赋值函数指定一个对象

要以这种方式访问
$vars.title
,您应该提供一个数组:

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

Smarty是否显示错误?