2011-02-23 73 views
1

考慮一個名爲render_thing視圖,這是我從控制器加載像這樣:笨呼叫負載>視圖之間共享數據

$html = $this->load->view(
    'render_thing',     
    array(
    'someParam' => $globalParam 
    'permissionMode' => 'guest' 
), 
    true 
); 
log($html); 

後來在同一控制器,I再次加載的視圖,只是我請勿覆蓋可選的permissionMode參數。我假設在查看代碼中,$permissionMode將是unset

$moreHtml = $this->load->view(
    'render_thing',     
    array(
    'someParam' => 'blablabla' 
), 
    true 
); 

然而,在render_thing視圖代碼,在第二呼叫,$permissionMode仍然'guest'。你能告訴我這裏發生了什麼嗎?

謝謝!

回答

2

從Loader.php,Loader::_ci_load在笨源...

/* 
    * Extract and cache variables 
    * 
    * You can either set variables using the dedicated $this->load_vars() 
    * function or via the second parameter of this function. We'll merge 
    * the two types and cache them so that views that are embedded within 
    * other views can have access to these variables. 
    */ 
    if (is_array($_ci_vars)) 
    { 
     $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); 
    } 
    extract($this->_ci_cached_vars); 

所以,這將是爲什麼參數仍設置。 load_vars不是一種方法,但vars是;問題在於它沒有提供擦除緩存的功能。因此,由於CodeIgniter仍然兼容PHP4,因此您可以始終這樣做:$this->load->_ci_cached_vars = array();

1

我有同樣的問題,並找出Loader.php中的問題,如下所示;

/* 
* Extract and cache variables 
* 
* You can either set variables using the dedicated $this->load_vars() 
* function or via the second parameter of this function. We'll merge 
* the two types and cache them so that views that are embedded within 
* other views can have access to these variables. 
*/ 
if (is_array($_ci_vars)) 
{ 
    $this->_ci_cached_vars = array_merge($this->_ci_cached_vars, $_ci_vars); 
}else{ 
    $this->load->_ci_cached_vars = array(); 
} 
extract($this->_ci_cached_vars);