包菜兄 2013-02-03 18:17:04 3590次浏览 0条回复 0 0 0

category表和post表是多对多,有个中间表relationships,分别记着category_id和post_id Post.php model中 有关系 'cids'=>array(self::HAS_MANY,'Relationships','post_id'), Category.php model中有方法:

static public function getAllCategory(){
    return CHtml::listData(self::model()->findAll(), 'id', 'name');
}

比如现在我要更新一条数据,这条数据的栏目有两个,假设该文章id是21,是属于两个栏目,那么在relationship表中的数据就应该是

id     post_id category_id
1         21          1
2         21          2

其中id是流水,该文章的category是1和2. 该栏目的数据我通过建立Relationship.php的AR能够获取,

_from中表单我是这么写的:

<div class='row'>
    <?php echo $form->labelEx($model,'cid'); ?>
    <?php echo $form->checkBoxList($model,'cid',
        Category::getAllCategory(),array(
            'style'=>'display:inline;',
            'separator'=>"<br />\n",
            'template'=>'{input}{label}',
            'labelOptions'=>array('style'=>'display:inline')));
    ?>
    <?php echo $form->error($model,'cid'); ?>
</div>

问题是我在_form 中不知道要肿么将数据填进去?就是我在更新数据的时候,栏目应该选中才对

    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册