I'm finishing my first web based app using Laravel 4 and it's almost done, the issue I have is the following:
I'm trying to make custom 404 error view with dynamic content, I have a form with a couple of selects populated from a DB, I do this thru the Base controller like this:
protected function setupLayout() {
if (!is_null($this->layout)) {
$this->layout = View::make($this->layout);
}
View::composer('templates.partials.footer', function ($view) {
$languages = array('' => 'Choose Language Pair:') + Language::orderBy('order')->lists('name', 'id');
$view->with('languages', $languages);
});
}
This form needs to be present in the entire web and it works fine in all the views but the error one, when I enter an unvalid url an php error shows telling me that the variable $languages in the footer view is undefined. I tried taking out the footer from the default template and it works wonderful.
Here is how I'm handling my errors: -in the global.php
App::error(function(Exception $exception, $code) {
//Log::error($exception);
return BaseController::handleError($code);
});
-and the method in the BaseController:
protected function handleError($code) {
//return View::make('404' . $code);
switch ($code) {
case 403:
return Response::view('404', array(), 403);
case 404:
return Response::view('404', array(), 404);
case 500:
return Response::view('404', array(), 500);
default:
return Response::view('404', array(), $code);
}
}
As you can see I've tried using Response::view but it seems that it doesn't load the View::composer that sends the data to the form, and the other way around using return View::make isn't good either because I need it to be an error for SEO reasons.
So...
Is there a way to send my dynamic data to my error view while getting the errors in the browser?
Thanks before hand!