Hi, I am new to yii structure and now I am trying to create a dropdownlist from a linked table. I have a table "News" [... many fields, categories] and "NewsCategories" [id, category_name]. In the form for creating a new entry in News, I want to create a dropedownlist in the category field, when the user can select category_name, but the category identifier should be the recorder in the new entry.
Please help me with this. Sorry for my English. I hope I explain it clearly.
This is how I created the relationship
Model News.php
public function relations() {
Model NewsCategories.php
public function relations() {
And how I am trying to create a dropdownlist:
<?php echo $form->dropDownList($model,'category',CHtml::listdata(News::model()->with('category')->findAll(),'id','category_name'),array('empty'=>'(Select a category')));?>
source share