0

私は CakePHP で次の選択ボックスを持っています。

//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 ) )

だから私は2つの問題があります

  1. アイテム自体ではなく、アイテムのインデックスが選択されています
  2. setFlash ウィンドウには常に「1」が表示されます。リストボックスを機能させた後、文字列操作を行う必要があり、出力を確認できてうれしいです。

更新 - /Cake/View/Helper/FormHelper.php に入り、掘り下げました

次の行で print_r を実行しました

$attributes = $this->_initInputField($fieldName, array_merge(
        (array)$attributes, array('secure' => self::SECURE_SKIP)
    ));

その結果、

Array ( [value] => 0 [class] => [name] => data[Users][Location] [id] => UsersLocation )

渡される値は 0 です。場所がどこにも表示されません

4

2 に答える 2