shii
(Evil Evo)
1
Hello everybody,
I am trying to insert a new Comment into the Comment table with the Create Controller generated by gii.
Everything works except that the form field parent_id is being ignored.
I am filling out every field and every field is being saved in the database except the field parent_id.
The field parent_id is always saved as 0 although i entered other ids.
However, when I try to assign a value directly in the Controller with $model->parent_id = 1; it works.
So somehow the value from the form isn’t being transfered to $model->parent_id unlike all other fields.
Why is that so?
Any help is greatly appreciated
ani
(Aneesh)
2
The parent_id have any other relationships? Do you enter the parent_id directly in the form?
yiqing95
(Yiqing 95)
3
may be in the database this field is a boolean/bool type .
and you 'd better also see the rules for this field in the Comment model .
<?php
class CommonMethods {
private $data = array();
public function makeDropDown($parents)
{
global $data;
$data = array();
foreach($parents as $parent)
{
$data[$parent->hostel_information_id] = $parent->hostel_name;
$this->subDropDown($parent->children);
}
return $data;
}
public function subDropDown($children,$space = ‘—’)
{
global $data;
foreach($children as $child)
{
$data[$child->hostel_information_id] = $space.$child->hostel_name;
$this->subDropDown($child->children,$space.'---');
}
}
}
?>
make one file in component folder.
use following code in form file.
<?php $parents = HostelInformation::model()->findAll('hostel_parent_id = 0');
$cm = new CommonMethods();
$data = $cm->makeDropDown($parents);
echo $form->dropDownList($model,'hostel_parent_id',$data,array('empty'=>'--------Select------')); ?>
above code is developed according to my requirement. you can change according to your requirement.