2

他のコントローラーによって拡張された次のクラスを持つ

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;

echo $role私の中で、いいねをするだけですheader.blade.php

4

1 に答える 1

1

私は次のことをしてしまいました。

コントローラ

// Example of variable to set
$this->layout->body_class = 'user-register';

$view = View::make('modules.user.register', array(
    'success' => true,
));

$this->layout->content = $view;

私のdefault.layout.php見解

<body class="<?php echo isset($body_class) ? $body_class : '' ;?>">

    @include('partials.header')

    {{ $content }}

    @include('partials.footer')

変数は、ビュー内の他のコンテキストで簡単に使用できます。

于 2013-06-12T05:20:17.987 に答える