0

私がここで間違っていることを理解することはできません:

私はコントローラーを持っています:

$this->set('sizes', array('4x4'=>'4x4','6x6'=>'6x6','8x8'=> '8x8')); 

ビューには次のものがあります。

echo $this->Form->input('size');

ドロップダウンボックスがアレイとともに正しく表示されます。

同じ機能の下の同じコントローラーで私は持っています:

$this->set('states', 'this state'); 

ビューには次のものがあります。

echo $this->Form->input('state');

ただし、「状態」テキストボックスには情報が含まれていません。状態行を次のように変更した場合:

$this->set('states', array('this state')); 

ドロップダウンボックスが単一のエントリとともに表示されます。ドロップダウンボックスではなく、テキストボックスに情報を入力したいと思います。助言がありますか?

4

1 に答える 1

0

Just to be sure, have you tried setting the type of the form input?

$this->Form->input('state', array('type' => 'text'));

Probably the input isn't populated because it uses the singular "state" instead of "states". It has also always been my understanding that form fields are populated with data from the $this->data/$this->request->data array. Selects, checkboxes, etc. are a special case, because they have an options array, which in the case of your size input is populated with $sizes.

So let's say your form model is Order and you set $this->request->data in your OrdersController:

$this->request->data['Page']['state'] = 'this state';

If that doesn't work for you for some reason, you can always set the value of the input explicitly:

$this->Form->input('state', array('value' => $states));
于 2012-09-27T10:01:51.250 に答える