Seems to work quite well, with one major problem;
Let’s say you want to be able to generate a checkBoxList(or any selectable list) on your services form as well as the Portofolio form.
the code for this would look something like this:
Service Model:
public $portofolioIds = array();
public function afterFind()
{
if (!empty($this->portofolios))
{
foreach ($this->portofolios as $n => $portofolio)
$this->potofolioIds[] = $portofolio->id;
}
parent::afterFind();
}
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('status, description, title, url, services', 'required'),
array('status', 'numerical', 'integerOnly' => true),
array('title, url', 'length', 'max' => 255),
array('portofolioIds', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, status, description, title, url', 'safe', 'on' => 'search'),
);
}
Service Controller:
if (isset($_POST['Service']))
{
$model->attributes = $_POST['Service'];
$model->services = $model->portofolioIds;
if ($model->save())
$this->redirect(array('service/admin'));
}
And finally the _form View
<div class="row oneLineLabel">
<?php echo $form->labelEx($model, 'portofolios'); ?>
<?php echo $form->checkBoxList($model, 'portofolioIds',
CHtml::listData(Portofolio::model()->findAll(), 'id', 'name'),
array('checkAll' => 'Check All')); ?>
<?php echo $form->error($model, 'portofolios'); ?>
</div>
The problem seems that this generates an infinite loop of afterFind functions, how would one go about resolving this.
Take into account that I am not an expert with yii.