2014-06-21 49 views
0

使用laravel我設置一個變量在控制器的佈局:Laravel不確定的變量,但變量定義

$this->layout->title = 'Foo'; 
$this->layout->content = View::make('foo.bar'); 

但是,當我在模板中使用$title我得到一個undefined錯誤:

<title>{{{ $title }}}</title>

但是,如果使用條件

<title>{{{ $title or 'Default' }}}</title>

我得到沒有錯誤,它使用$title變量。

回答

-1

根據Laravel API爲Illuminate\View\View

protected string  $view The name of the view. 
protected array  $data The array of view data. 

所以將數據傳遞到通過控制器的特性來看,你需要做的:

$this->layout->data = array('title' => 'Foo');