Answer the question
In order to leave comments, you need to log in
How to correctly form the parameter for "Form::select"?
Good day to all.
I work with kohana 3.3.2
There is a table of departments (id., name of the department, subordinate to the department), with the fields "id", "name", "main_dep_id".
The "main_dep_id" field refers to the "name" field of another "id" of the same table (i.e. a department is part of another department, etc.).
In the department edit controller handler, I wrote:
...
$id = (int) $this->request->param('id');
$one_department_a = ORM::factory('department', $id)->as_array();
$this->departments_a = array();
$this->departments_a1 = array();
foreach($this->departments_o as $department)
{
$this->departments_a[$department->id] = $department->abbreviation;
$this->departments_a1[$department->id]= $department->name;
}
...
…
<select size="1" name="main_dep_id">
<?php foreach($departments as $department):?>
<?php if(($department->id) == $one_department_a['main_dep_id']):?>
<option selected value="<?=($department->id)?>"><?=$department->name?></option>
<?php else:?>
<option value="<?=($department->id)?>"><?=$department->name?></option>
<?php endif?>
<?php endforeach?>
</select>
…
Answer the question
In order to leave comments, you need to log in
Probably not the third parameter but the second one? It should look like this:
$options = array(
'value1' => 'name1',
'value2' => 'name2',
);
$options = array(
'group1' => array(
'value1' => 'name1',
'value2' => 'name2',
),
'group2' => array(
'value3' => 'name3',
),
);
$selected = 'value1';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question