i have two mdoel 1)Issue
2)Category
and in the issue view page, i am able to get the data into Dropdownlist form tbl_category database
<div>
<?php echo $form->labelEx($model, 'category'); ?>
<?php echo CHtml::activeDropDownList($model, 'category_id',Category::model()->getCategoryOptions()); ?>
<?php echo $form->error($model, 'category'); ?>
</div>
but the data is not inserting into tbl_issue database
plz reply
thanks in advance
zaccaria
(Matteo Falsitta)
November 2, 2010, 1:49pm
2
Your function getCategoryOptions() should return an array like that:
array('primaryKey'=>'displayData')
You can create it with CListData:
<?php echo CHtml::activeDropDownList($model,'category_id',
CHtml::listData(Category::model()->findAll(),
'primaryKey','optionName'));
You can check if $_POST[‘modelId’][‘category_id’] is corrected, if it is so it means that the attribute category_id is not safe, you have to add to the list of safe attributes.
Adding a bit more explanation to the correct answer of Zac, I would say that in your Controllers Action you receive the post also like:
$model->attributes = $_POST[‘modelID’];
$model->save();
if it doesnt save do in your rules():
array(‘category_id’,‘safe’),
best
reijino1
(Thiensutinhyeu 0088)
January 3, 2012, 1:55pm
6
i have two model
1)Tree
2)TreeType
_form.php(tree.php)
echo CHtml::activeDropDownList($model,'id_typetree',$model->getTypeTree());
Tree.php
public function getTypeTree()
{
$TypeArray = CHtml::listData(Treetype::model()->findAll(array('order' => 'name')), 'id_typetree', 'name');
return $TypeArray;
}
the data is not inserting into tbl_tree database. ???
helf me…!
thanks for reply
jacmoe
(Jacob Moena)
January 6, 2012, 12:07pm
8
Er, Richdad.tx - does this mean you’ve got it solved?
[b]
[/b]