【发布时间】:2013-01-16 16:01:45
【问题描述】:
具有以下由其他控制器扩展的类
class Admin_Controller extends Base_Controller
{
static $admin_layout = 'admin.layouts.default';
public function __construct()
{
parent::__construct();
$role_object = User::find(Auth::user()->id)->roles()->get();
$role = $role_object[0]->attributes['name'];
如:
class Admin_Draws_Controller extends Admin_Controller
{
public $restful = true;
public function __construct()
{
$this->layout = parent::$admin_layout;
parent::__construct();
}
public function get_index()
{
$view = View::make('admin.templates.draws');
$this->layout->content = $view;
}
}
如何将$role 变量发送到admin.layouts.default,以便在加载视图时获得它?
“全局”$role 变量的意义在于避免在我的所有View::make() 中调用它,如下所示:
$view = View::make('admin.templates.articles',
array(
'fields' => $fields,
'data' => $results,
'links' => $links,
'role' => 'role here'. // I don't want to add this where ever I call the View::make
)
);
$this->layout->content = $view;
然后在我的header.blade.php 中进行echo $role 之类的操作
【问题讨论】:
标签: php variables inheritance views laravel