How can i set selection in dropdown in cakephp
-
02-07-2021 - |
문제
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/
제휴하지 않습니다 StackOverflow