I’m new to Yii and in trouble with relations and a special view for editing and creating.
My entities:
customer(id,…)
profile(id,customer_id,…)
device(id,customer_id,profile_id,…)
app(id,…)
device_app(device_id,app_id)
profile_app(profile_id,app_id)
app_label(id,app_id,…)
My relations:
Customer:
devices => array(self::HAS_MANY, Device, customer_id),
profiles => array(self::HAS_MANY, Profile, customer_id),
Profile:
devices => array(self::HAS_MANY, Device, profile_id),
customer => array(self::BELONGS_TO, Customer, customer_id),
Device:
customer => array(self::BELONGS_TO, Customer, customer_id),
profile => array(self::BELONGS_TO, Profile, profile_id),
apps => array(self::MANY_MANY, App, profile_app(profile_id, app_id)),
App:
appLabels => array(self::HAS_MANY, AppLabel, app_id),
devices => array(self::MANY_MANY, ‘Device’, device_app(app_id, device_id)),
profiles => array(self::MANY_MANY, Profile, profile_app(app_id, profile_id)),
DeviceApp:
no relations
ProfileApp:
no relations
AppLabel:
app => array(self::BELONGS_TO, App, app_id),
I can create/edit customers, devices so far. But now i have a problem: when creating a profile it should be possible to associate apps to it. I tried to solve this with CActiveForm and a checkBoxList and ran in two major problems. On the one hand is such a list not very usefull, because there are about hundreds of apps in this list and on the other hand i didn’t ‘find’ the right code for checked oder unchecked boxes. Code from this(_form in profile):
$form->checkBoxList($model,‘id’, CHtml::listData(App::model()->findAll(array(‘order’=>‘package_name’)), ‘id’,‘package_name’),array(‘multiple’=>‘multiple’,‘template’=>’<li>{input} {label}</li>’,‘labelOptions’=>array(‘style’=>‘display:inline’),))
This will compare the id of apps with id of profile…
I think about a better way to make a view with CGridView, where you can see all active apps first and afterwards all other apps with checkboxes and a routine to save them.
Any ideas or advices much appreciated!