2014-09-03 122 views
0

我在HomeController.php2佈局在一個控制器

// other pages layout 
protected $layout = "layout"; 

protected $layout2 = "layout2"; 
    // empty user object 
protected $user; 

// constructor 
public function __construct() 
{ 
} 


public function getAbout() 
{ 

// share main home page only 
$this->layout->content = View::make('about'); 

} 

// THIS IS NOT WORKING >>>> 
public function getAboutnew() 
{ 

// share main home page only 
$this->layout2->content = View::make('about'); 

} 

所以getAboutNew我想使用佈局2,但我得到了一個錯誤:

ErrorException (E_UNKNOWN) Attempt to assign property of non-object

如何解決這一問題?

+0

$這 - >佈局2是一個字符串,而不是一個對象。 – 2014-09-03 19:31:45

+0

$ this-> layout是一個對象,可以工作嗎? – user3150060 2014-09-03 19:32:08

回答

1

您需要更改,HomeController的擴展名。 在你BaseController您有:

protected function setupLayout() 
{ 
    if (! is_null($this->layout)) 
    { 
     $this->layout = View::make($this->layout); 
    } 
} 

此轉換$this->layout(字符串)到您需要的視圖對象。

修正:

// BaseController, returning respective views for layouts 
protected function setupLayout() 
{ 
    if (! is_null($this->layout)) 
    { 
     $this->layout = View::make($this->layout); 
    } 

    if (! is_null($this->layout2)) 
    { 
     $this->layout2 = View::make($this->layout2); 
    } 
} 



// HomeController 
public function getAbout() 
{ 
    $this->layout->content = View::make('about'); 
} 


public function getAboutnew() 
{ 
    $this->layout2->content = View::make('about'); 
    return $this->layout2; 
    // Note the additional return above. 
    //You need to do this whenever your layout is not the default $this->layout 
} 
+0

非常感謝您的幫助 – user3150060 2014-09-03 23:23:34