我有以下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