checkbox foreign key belongs to many in Yii -
i'm new yii framework utilize help something. lets got table in database post, 1 of fields type. in table got lot of types this:
table type:
id name 1 politic 2 sport 3 espiritual
table post:
id title 1 politic in barsovia 2 god exist! 3 del po win in rotterdam
table post_type
id id_post id_type 1 1 1 2 2 3 3 3 2
i have relationships in type
'posttype' => array(self::has_many, 'post_type', 'id_type'),
i have relationships in post
'posttype' => array(self::has_many, 'post_type', 'id_post'),
i wan example
question:
how create list of checkboxes table type
how utilize activecheckboxlist width cadvancedarbehavior
you can utilize chtml::checkboxlist() (or chtml::activecheckboxlist() or wrapper in cactiveform). example, in controller, can have line retrieve related types:
$types = chtml::listdata($model->posttype, 'id', 'name'); // prepare info check box list // rest of controller code ... $this->render('create', array( 'model' => $model, 'types' => $types, ));
in view, can utilize cactiveform::checkboxlist() generate check boxes:
<?php echo $form->checkboxlist($model, 'type', $types); ?>
also, recommend create relationships more user-friendly changing names: should have "posts" name of relation in type model, , "types" name of relation in post model.
checkbox yii foreign-keys one-to-many belongs-to
No comments:
Post a Comment