I’m sorry for the late reply.
So,here is the more detailed case. One member can subscribe to several category, and the category can have several member attached to it. Which means the relations is many to many. So I created a junction table tbl_subscribed_member.
This is my member.php which is the model :
class Member extends VeevouAR
{
......
public $categoryIds;
public function afterFind() //Used to retrieve the categories of the selected member
{
$this->categoryIds = array_keys($this->categories);
parent::afterFind();
}
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'categories' => array(self::MANY_MANY, 'BusinessCategory', 'tbl_subscribed_member(member_id, bc_id)','index'=>'bc_id'),
);
}
........
}
And this is my BusinessCategory.php :
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'members' => array(self::MANY_MANY, 'Member', 'tbl_subscribed_member(bc_id, member_id)'),
);
}
This is my _update.php
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'member-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'member_username'); ?> <br/>
<?php echo $form->textField($model,'member_username',array('size'=>20,'maxlength'=>20)); ?>
<?php echo $form->error($model,'member_username'); ?>
</div>
<div class="row">
Please choose your category :
<?php echo CHtml::activeCheckBoxList(
$model,
'categoryIds',
Chtml::listData(BusinessCategory::model()->findAll(),'bc_id','bc_name'));?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
and this is my controller :
public function actionUpdate($id)
{
$member = $this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Member']))
{
$member->attributes = $_POST['Member'];
print_r($member['categoryIds']);
}
}
Now, when i do this, it only show the old value, not the one that i just ticked. There must be some mistake but dunno where it is. Any advice? =) Thanks