Wednesday, June 19, 2013

Re: Can anyone help me with editing post_tags ???

this is a part of code for adding topic with tags

$save = $this->Topic->save($data['Topic']);
if($save){
$tags = explode(',', $data['Topic']['tags']);
foreach($tags as $tag){
$tag = strtolower(trim($tag));
if($tag){
$foundTag = $this->Tag->find(
'first', array(
'conditions' => array(
'Tag.title' => $tag
)
)
);
if($foundTag){
$topicTags['TopicTag']['tagId'] =
$foundTag['Tag']['id'];
}else{
$this->Tag->create();
$savedtag = $this->Tag->save(array('Tag'
=> array('title' => $tag)));
$topicTags['TopicTag']['tagId'] =
$savedtag['Tag']['id'];
}
$topicTags['TopicTag']['topicId'] =
$save['Topic']['id'];
$this->TopicTag->create();
$this->TopicTag->save($topicTags);
}
}

i have problems with editing,, have to find all tag id before editing and
after editing, something like that,
there's three tables
topics, tags and topic_tags with topicId and tagId,
sorry for bad explanation
thanks



--
View this message in context: http://cakephp.1045679.n5.nabble.com/Can-anyone-help-me-with-editing-post-tags-tp5715315p5715319.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: