I have a function in a controller that first checks a to see did the user submit a form from the website, facebook or mobile.
It then changes the layout as needed. But with mobile I want to load a different view as the display is quite different.
My problem is that the data from the controller is not getting passed to the new view. I get undefined variables and arguments for all the php within the view. The php code is exactly the same in all views, it is only the layout of the div’s I am changing in the mobile view.
I cannot see why this might be happening?
Controller
function availability() {
if ($_REQUEST['from'] == 'facebook') {
$this->layout = 'facebook';
}elseif ($_REQUEST['from'] == 'website'){
$this->layout = 'res';
}elseif ($_REQUEST['from'] == 'mobile'){
$this->layout = 'mobile_layout';
$this->render( 'mobile' );
};
$this->newSession();
$msg[0] = array(); // 0 = bad messages
$msg[1] = array(); // 1 = good messages
if(isset($_REQUEST['date_start'],$_REQUEST['date_end'])){
$data['Availability']['date_start'] = $_REQUEST['date_start'];
$data['Availability']['date_end'] = $_REQUEST['date_end'];
}
if(!isset($_REQUEST['voucher_code'])){
$_REQUEST['voucher_code'] = 0;
}
One of the errors within the mobile view, line 83 in the res_controller is $this->render( ‘mobile’ );:
Notice (8): Undefined variable: availability [APP/views/res/mobile.ctp, line 16]
Code | Context
include - APP/views/res/mobile.ctp, line 16
View::_render() - CORE/cake/libs/view/view.php, line 731
View::render() - CORE/cake/libs/view/view.php, line 426
Controller::render() - CORE/cake/libs/controller/controller.php, line 909
ResController::availability() - APP/controllers/res_controller.php, line 83
Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 204
Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83
When you call
Controller::render, I believe the view is rendered (and returned) immediately. So, before that call you have to set any variables the view is expecting.