我有以下CakePHP選擇框。CakePHP - 選擇框項目在POSTED數據中沒有正確顯示
//Users/settings.ctp
$options = array('NYC', 'LA');
echo $this->Form->create('Location');
echo $this->Form->input('Location', array('type' => 'select', 'options' => $options));
echo $this->Form->end(__('Submit'));
在UsersController我
public function settings($id = null){
if ($this->request->is('post')) {
$location = $this->request->data;
//$location = $location['Location']['Location'][0];
$this->Session->setFlash(__(print_r($location))); //displays '1' in the alert no matter the selection
}
}
當我使用的print_r對原始數據就說明如下。
Array ([Location] => Array ([Location] => 0))
所以,我有兩個問題
- 該項目的索引被選中,而不是項目本身
- 的setFlash窗口總是顯示「1」。我需要做一些字符串操作後,我得到的列表框工作,很高興看到輸出。
更新 - 我走進/Cake/View/Helper/FormHelper.php並做了一些挖
我做了以下行
$attributes = $this->_initInputField($fieldName, array_merge(
(array)$attributes, array('secure' => self::SECURE_SKIP)
));
這就造成了一個
的print_rArray ([value] => 0 [class] => [name] => data[Users][Location] [id] => UsersLocation)
傳遞的值爲0,我沒有看到任何位置
不要在裏面setFlash調試需要這麼格式化爲
的數組,而只是做了'調試($這個 - >請求 - >數據)'來查看發佈的數據。 – Oldskool 2013-04-20 23:34:32
這和我上面列出的print_r是一樣的。它發送索引,而不是項目。 – user1443519 2013-04-20 23:43:55