0
我在控制器中有一個函數,首先檢查用戶是否從網站,臉書或手機提交表單。cakephp更改視圖不傳遞來自控制器的數據
然後它根據需要更改佈局。但隨着移動我想加載一個不同的看法,因爲顯示器是完全不同的。
我的問題是來自控制器的數據沒有傳遞到新的視圖。我得到了視圖中所有php的未定義變量和參數。 php代碼在所有視圖中都完全相同,它只是我在移動視圖中更改的div的佈局。
我看不出爲什麼會發生這種情況?
控制器
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是$這 - >渲染( '移動');:
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
我應該把網站,臉譜和移動檢查功能的末尾,所以,功能後,設置VAR和進行計算?我已經剝離了其他視圖作爲測試,是的問題是$ this-> render('mobile');作爲它自己的移動工作。 –
你應該嘗試。 – bfavaretto
感謝您的幫助 –