cakephp change view does not pass data from controller
我在控制器中具有一个功能,该功能首先检查a以查看用户是否从网站,facebook或手机提交了表单。
然后根据需要更改布局。但是对于移动设备,我希望加载不同的视图,因为显示效果大不相同。
我的问题是来自控制器的数据没有传递到新视图。我在视图中得到了所有PHP的未定义变量和参数。 php代码在所有视图中都完全相同,只是在移动视图中我正在更改的div的布局。
我不知道为什么会这样?
控制器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 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; } |
移动视图中的错误之一,res_controller中的第83行是$ this-> render('mobile'); ::
1 2 3 4 5 6 7 8 9 10 11 | 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 |
当您调用