php - How to update a jointable in CakePHP, manually -
I am a newbie with CakePHP. I have two tables: contact and tag, and an HABT table contact_tag adding the user tag.
Because people can be able to do it in delicious.com. They get a list of tags like they write. They can just add new tags by typing them. I'll see the tag table to see which tags already exist and which are not. The new ones should be added to the tag table and the insert id has been added to an array. Then I want to use these tag IDs to update contact tags. Bus. These are the two functions I have created:
/ ** This function checks for existing tags and creates new tags @param string (tags separated by commas) @ Return Array (Of id) ** / function save and cutlet ($ tag) {$ tag = explosion (",", $ tag); // Create an array of tags $ idArray = array (); Forex Currency ($ tag as $ tag) {$ count = $ this-> Find ('calculation', array ('conditions' = & gt; array ('name' = & gt; $ tag); if ($ count === 0) {$ this-> (;); if ($ This- & gt; Save ($ Tag)) {$ idArray [] = $ this-> getInsertID ();}} and {$ idArray [] = $ this-> getID ();}} Return $ IdArray;} / ** This function updates the relational table @ piram array (for protection of this array) and the context tag function @ pirades int (contact id) ** / function update codecabletable ($ idArray, $ contactId) { Foreach ($ idArray $ tagId) ($ count = $ this- & gt; ContactTag- & gt; ANGI (array ('tag_id' = $ gtId, 'contact_id' = & gt; $ contactId)); if ($ count = == 0) {( ); $ This-> Contact-> Save- (array ('contact_id' = & gt; $ contactId, 'tag_id' = & gt; $ tagId))}}}}
Neither $ The-> ContactTag-> is now, $ this-> ContactTag-> Make, $ this-> ContactTag-> Savings is working ... am I missing something?
view this post by teknoid
Comments
Post a Comment