systemiv
(Systemiv)
1
Hi!
I have a problem. I myself chose to use checkboxes for tags. I am a beginner, and i do not like to turn the table relationships.
Here are the approximate outline of the code:
public function afterSave(){
if(parent::afterSave()){
if(!empty($this->tags)){
foreach($this->tags as $tag){
$this->tags.id_tag = $tag->id_tag;
$this->tags.id_post = $this->id_post;
}
}
}
}
For all the right ideas, but does not work.
weavora
(Yury Tolochko)
2
systemiv
(Systemiv)
3
Solved the problem:
public function afterSave(){
if(parent::afterSave()){
$sql = 'DELETE FROM tbl_post_tag WHERE id_post = '.$this->id_post;
$command = Yii::app()->db->createCommand($sql);
$command->execute();
foreach($this->tags as $tag){
$sql = 'INSERT INTO tbl_post_tag (id_tag, id_post) VALUES ('.$tag.', '.$this->id_post.')';
$command = Yii::app()->db->createCommand($sql);
$command->execute();
}
}
}
}
systemiv
(Systemiv)
4
but, if i update article. always select first checkbox. why?