2
我想要一个变量传递给我“主人”的布局:Laravel 4 +可变传递掌握布局
//views/dashboard/layouts/master.blade.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
@yield('site.body');
{{{ isset($test) ? $title:'Test no exists :) ' }}}
</body>
</html>
现在在我的DashboardController:
class DashboardController extends BaseController
{
public $layout = "dashboard.layouts.master";
// this throw error : Cannot call constructor
//public function __construct()
//{
// parent::__construct();
// $this->layout->title = 'cry...';
//}
// this throw error : Attempt to assign property of non-object
// and I understand it, coz $layout isn't an object
//public function __construct()
//{
// $this->layout->title = 'cry...';
//}
public function action_doIndex()
{
$this->layout->title = 'this is short title';
$this->layout->body = View::make('dashboard.index');
}
public function action_doLogin()
{
//$this->layout->title = 'this is short title'; // AGAIN ???
$this->layout->body = View::make('dashboard.forms.login');
}
public function action_doN()
{
// $this->layout->title = 'this is short title'; // AND OVER AGAIN ?!?!
}
}
我想设置一次$ title变量,以及我想要做的时候 - 覆盖它。/
如何做到这一点: 现在我必须在我调用另一个方法每次设置变量?如何只为这个'主'布局设置$ title变量?
Symphony2有前()/()方法之后 - 有什么laravel?
好的答案,正是我所期待的。 –