【发布时间】:2014-05-22 16:36:05
【问题描述】:
我正在尝试将变量传递给我的“主”布局:
//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 有 before() / after() 方法 - laravel 有什么?
【问题讨论】: