0

モデルから 2 つの配列を作成します。1 つはユーザーから既に選択されている値で、2 番目の使用可能な値はユーザーが選択することもできます。これは編集ページ用です。複数選択入力ボックスに両方のモデルの値を入力したいが、既に選択されている値 (1 番目の配列) を強調表示したい。それはモデルをうまく作成し、array_merge() を使用して両方の配列をオプションとしてマージしますが、選択したものは正しいフィールドを強調表示しません。任意のヒント?

 // Controller:
 $ivrNumbersAvail = $this->Survey->SurveyIvrNumber->find("list",array("conditions" => array("OR" => array("SurveyIvrNumber.survey_id" => array($id)))));
 $ivrNumbersSelected = $this->Survey->SurveyIvrNumber->find("list",array("conditions" => array("OR" => array("SurveyIvrNumber.survey_id" => array(0)))));

 // In the view:
 echo $this->Form->input('SurveyIvrNumbers.id',array(
                            'empty' => '-- Select IVR Number(s) --',
                            'options' => array_merge($ivrNumbersAvail,$ivrNumbersSelected),
                            'selected' => $ivrNumbersSelected,
            'class' => 'textbox',
                            'multiple' => true,
            'div' => array(
                    'class' => 'field'
            ),
                'label' => array(
                'class' => 'label-tooltip',
                'title' => '', //tool tips
                'text' => 'IVR Numbers: (you can select multiple numbers)'

                ),
                'after' => '<p class="field-help"></p>'
        ));
4

1 に答える 1

1

現在編集中のレコードに設定$this->request->dataすると、CakePHP は自動的にこのデータを入力します!

// CONTROLLER
// this line sets the data
$this->request->data = $this->Survey->read(null, $id); 

// this passes the SurveyIvrNumbers to the view, (you can put any options on to this)
$this->set('SurveyIvrNumber',$this->Survey->SurveyIvrNumber->find('all')); 

// VIEW
// CakePHP does the rest
echo $this->Form->input('SurveyIvrNumbers',array( 
    'empty' => '-- Select IVR Number(s) --', // plus other options
);
于 2012-05-25T09:34:39.413 に答える