2014-06-21 43 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');