2

Having the following class that is extended by other controllers

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'];

such as:

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;
    }
}

How can I send the $role variable to admin.layouts.default so I can have it when ever the view is loaded?

The point of "global" $role variable is to avoid to have to call it in all of my View::make() like the following:

$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;

and just do an echo $role like, in my header.blade.php

1 Answer 1

1

I ended up doing the following, which works.

Controller

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

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

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

My default.layout.php view

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

    @include('partials.header')

    {{ $content }}

    @include('partials.footer')

The variable, can be easily used in any other context within the view.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.