Laravel - public layout not needed in every function
Posted
by
fischer
on Stack Overflow
See other posts from Stack Overflow
or by fischer
Published on 2012-09-30T09:33:36Z
Indexed on
2012/09/30
9:37 UTC
Read the original article
Hit count: 543
I have just recently started working with Laravel. Great framework so far! However I have a question.
I am using a layout template like this:
public $layout = 'layouts.private';
This is set in my Base_Controller:
public function __construct(){
//Styles
Asset::add('reset', 'css/reset.css');
Asset::add('main', 'css/main.css');
//Scripts
Asset::add('jQuery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js');
//Switch layout template according to the users auth credentials.
if (Auth::check()) {
$this -> layout = 'layouts.private';
} else {
$this -> layout = 'layouts.public';
}
parent::__construct();
}
However I get an error exception now when I try to access functions in my diffrent controllers, which should not call any view, i.e. when a user is going to login:
class Login_Controller extends Base_Controller {
public $restful = true;
public function post_index()
{
$user = new User();
$credentials = array('username' => Input::get('email'), 'password' => Input::get('password'));
if (Auth::attempt($credentials))
{
} else {
}
}
}
The error I get, is that I do not set the content of the different variables in my public $layout. But since no view is needed in this function, how do I tell Laravel not to include the layout in this function?
The best solution that I my self have come a cross (don't know if this is a bad way?) is to unset($this -> layout);
from function post_index()
...
To sum up my question: how do I tell Laravel not to include public $layout
in certain functions, where a view is not needed?
Thanks in advance, fischer
© Stack Overflow or respective owner