systemiv
(Systemiv)
July 10, 2011, 10:09am
1
Hello. Please help to solve the problem.
There are three tables: tbl_posts, tbl_tags and table connection tbl_post_tag.
Communication spelled like this:
'tags' => array(self::MANY_MANY, 'Tag', 'tbl_post_tag(id_post, id_tag)')
When you create an article that I need to display all the available tags from the table tbl_tags, if the article is update, those tags which it already owned should be noted.
I tried through cycles, but then I learned about checkBoxList.
The main problem is that I do not know how to get data into checkBox.
Thank you!
perochak
(Amjad Mughal)
July 10, 2011, 1:32pm
2
Load the Tag Data from database in model
then use it using CHtml::checkBox
systemiv
(Systemiv)
July 10, 2011, 2:45pm
3
How? If I use $model->relation_name I receive an empty array.
For example in the view $model->tags come empty array.
How do I apply?
elbek
(Elbek Kamoliddinov)
July 10, 2011, 3:29pm
4
Is there are any data in tbl_post_tag related to $model ?
systemiv
(Systemiv)
July 10, 2011, 4:07pm
5
No, but I need to put check marks when the article is from this table. On the idea because if an empty array, so there should be no check marks?
Maybe someone has sample code representation using checkboxes?
Action my controller:
public function actionCreate(){
$model = new Post;
$tags = Post::model()->with('tags')->findAll();
if(isset($_POST['Post'])){
$model->attributes = $_POST['Post'];
if($model->save()){
$this->redirect(array('view', 'id' => $model->id_post));
}
}
$this->render('_form', array(
'model' => $model,
'tags' => $tags,
));
}
systemiv
(Systemiv)
July 10, 2011, 5:01pm
6
I tried this:
$tags = Tag::model()->findAll();
foreach($tags as $tag){
$label[] = $tag->text_tag;
$url[] = $tag->url_tag;
}
<?php echo $form->checkBoxList('myCheckBoxList', $model->tags, $label); ?>
Writes that: