data from Dropdownlist not inserting into database

i have two mdoel 1)Issue


and in the issue view page, i am able to get the data into Dropdownlist form tbl_category database


    <?php echo $form->labelEx($model, 'category'); ?>

    <?php echo CHtml::activeDropDownList($model, 'category_id',Category::model()->getCategoryOptions()); ?>

    <?php echo $form->error($model, 'category'); ?>


but the data is not inserting into tbl_issue database

plz reply

thanks in advance

Your function getCategoryOptions() should return an array like that:


You can create it with CListData:

<?php echo CHtml::activeDropDownList($model,'category_id',



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’];


if it doesnt save do in your rules():



its working

thanks for suggestion

its working fine

thanks for suggestion

i have two model




echo CHtml::activeDropDownList($model,'id_typetree',$model->getTypeTree());


 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

hi. ok.

thanks all

Er, Richdad.tx - does this mean you’ve got it solved? :)