문제

This is the dropdown code iam used:

$task_id = 2;
    $inr = 0;
                        $arr = array();
                        foreach ($options as $option){
                            $inr = $option['Employee']['employee_id'];
                            $arr[$inr] = $option['Employee']['first_name'].' '.$option['Employee']['last_name'];
                        }
                        echo $this->Form->input('assigned_to',      array(  'options' => array( $arr), 
                                                                    'empty' => '(choose one)',
                                                                    'div'=>'formfield',
                                                                    'label' => 'Assigned To',
                                                                    'error' => array(   'wrap' => 'div',
                                                                                        'class' => 'formerror'
                                                                                    )
                                                            ));

Its displayed with correct values in the $options.

But i need to select one option value usinsg cakephp code.

How can i do this?

That is i have a variable with value as :

$task_id = 2;

So how can i put selection to this option value?

If it is possible ?

도움이 되었습니까?

해결책

you mean default value? either use default key in the attributes for your form input element or the cleaner approach using the controller:

/* inside add/edit actions */
if (!empty($this->request->data)) {
    $this->Country->create();
    if ($this->Country->save($this->data)) {
        ...
    } else {
        ...
    }
} else {
    /* Now here you can put your default values */
    $this->request->data['Country']['active'] = 1;
    $this->request->data['Country']['lat'] = 0.0;
    ...
}

@see http://www.dereuromark.de/2010/06/23/working-with-forms/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top