It's likely because you're not calling create() before each save. In
any case, that code is a bit unweildy. You can save yourself a lot of
trouble by using TagBehavior:

http://bakery.cakephp.org/articles/view/simple-tagging-behavior

No muss, no fuss. Ain't the Bakery grand?

On Sun, May 3, 2009 at 7:11 PM, Kyle Decot <kdec...@gmail.com> wrote:
>
> I am attempting to make a loop that goes through all the tags a user
> has provided(comma seperated) and then if it's not already in the tags
> table, save it then add it to the event they just added. I can't seem
> to get it to work because $tag_id is always the same for all the tags
> so only the last tag is saved. Any thoughts?
>
> function __saveTags($tags=array(),$event_id="") {
>
>                if(!empty($tags)) {
>
>                        foreach($tags as $t) {
>
>                                
> if($this->Event->Tag->find('count',array("conditions"=>array
> ("Tag.type"=>"Event","Tag.name"=>$t))) == 0) {
>
>                                        $this->data = 
> array("Tag"=>array("type"=>"Event","name"=>$t));
>                                        $this->Event->Tag->save($this->data);
>                                        $tag_id = 
> $this->Event->Tag->getLastInsertID();
>                                        $this->Event->query("INSERT INTO 
> events_tags (tag_id,event_id)
> VALUES('" . $tag_id . "','" . $event_id . "')");
>
>                                }
>
>                        }
>
>                }
>
>        }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to