data from Dropdownlist not inserting into database

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

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

its working

thanks for suggestion

its working fine

thanks for suggestion

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

hi. ok.

thanks all

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

[b]

[/b]