itwy
(Itwybox)
July 4, 2011, 8:13pm
1
Hello,
Let’s say I have a tbl_article and tbl_category and I generated the CRUD for both. Now I need to have a drop down list for the category_id field in the article CRUD to show the category names instead of entering the category ID by hand. How can I do that?
I also have this set in my article model:
public function relations()
{
return array(
'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
);
}
How can I change this correctly:
<div class="row">
<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->dropDownList($model,'category_id',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />); ?>
<?php //echo $form->textField($model,'category_id'); ?>
<?php echo $form->error($model,'category_id'); ?>
</div>
Please help.
tri
(tri - Tommy Riboe)
July 4, 2011, 8:36pm
2
itwy:
Hello,
Let’s say I have a tbl_article and tbl_category and I generated the CRUD for both. Now I need to have a drop down list for the category_id field in the article CRUD to show the category names instead of entering the category ID by hand. How can I do that?
I also have this set in my article model:
public function relations()
{
return array(
'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
);
}
How can I change this correctly:
<div class="row">
<?php echo $form->labelEx($model,'category_id'); ?>
<?php echo $form->dropDownList($model,'category_id',<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' />); ?>
<?php //echo $form->textField($model,'category_id'); ?>
<?php echo $form->error($model,'category_id'); ?>
</div>
Please help.
You should replace the quotation marks with a listData call (or its results returned by a method you may add to the model class).
CHtml::listData(Category::model()->findAll(), 'category_id', 'category_name')
/Tommy