Where's the pr() statement? In the controller? Did you try with Debugger::log() immediately after adding the '51'?
On Fri, Jan 23, 2009 at 3:22 PM, kai <[email protected]> wrote: > > well, i tried that too and writing just as you have it, without the > conditional statement, does not seem to add the value 51 to the id > array. I'm using pr($this->data); to see what's in the array. > > On Jan 23, 10:38 am, brian <[email protected]> wrote: >> Sorry, I made a mistake. >> >> $this->data['Genre'][] = 51; >> >> should be >> >> $this->data['Genre']['id'][] = 51; >> >> You want to append '51' to the 'id' array, not the parent ('Genre'). >> >> How are you checking to see if the value was added? Try it like this >> and log your data array. >> >> if (isset($this->data['Genre']['id']) && >> is_array($this->data['Genre']['id']) && !in_array('51', >> $this->data['Genre']['id'])) >> { >> $this->data['Genre']['id'][] = 51; >> >> } >> >> Debugger::log($this->data); >> >> On Fri, Jan 23, 2009 at 12:30 AM, kai <[email protected]> wrote: >> >> > Even if i use array_push($this->data['Genre']['id'], 51); without the >> > conditional statement it still doesn't add 51 to the Genre id array. >> > $this->data['Genre'][] = 51; doesn't work either. I've tried a few >> > variations and can't get it to work. First I need to figure out how to >> > add values to the $this->data array and then I can focus on the >> > conditional statement. >> >> > On Jan 22, 5:42 pm, brian <[email protected]> wrote: >> >> if (isset($this->data['Genre']['id']) && >> >> is_array($this->data['Genre']['id']) && !in_array('51', >> >> $this->data['Genre']['id'])) >> >> { >> >> $this->data['Genre'][] = 51; >> >> // or, array_push($this->data['Genre'], 51); >> >> >> } >> >> On Thu, Jan 22, 2009 at 8:28 PM, kai <[email protected]> wrote: >> >> >> > In $this->data: >> >> > [Genre] => Array >> >> > ( >> >> > [id] => Array >> >> > ( >> >> > [0] => 2 >> >> > [1] => 55 >> >> > ) >> >> >> > ) >> >> > In sql: >> >> > WHERE `Genre_id` IN ('2', '55') >> >> >> > Yeah, I want to add to their selection, not override it. >> >> >> > On Jan 22, 5:21 pm, brian <[email protected]> wrote: >> >> >> If a user "chooses a genre" what does the data look like? Before your >> >> >> code does anything. Is it well formed? >> >> >> >> If you want to set ['Genre']['id'] to some value, what does the data >> >> >> look like before that? It seems like you're trying to override the >> >> >> user's selection, rather than add to it. Do you want to add ID=51 *in >> >> >> addition* to whatever genre ID the user passes? >> >> >> >> On Thu, Jan 22, 2009 at 8:09 PM, kai <[email protected]> wrote: >> >> >> >> > When a user submits a form I'm hoping to apply some logic to their >> >> >> > choice. The form takes user input and translates their selection into >> >> >> > conditions to use in a query. One part of the selection is the choice >> >> >> > to choose a genre. I'm hoping to say something like, if user chooses >> >> >> > one genre or more then also add 'this genre' to their query. I tried >> >> >> > something like: >> >> >> >> > if (!empty($this->data['Genre']['id']) and count($this->data['Genre'] >> >> >> > ['id']) > 0) { >> >> >> > $this->data['Genre']['id'] = 51; >> >> >> > } >> >> >> >> > but have found that $this->data['Genre']['id'] = 51; does nothing. >> >> >> > How >> >> >> > can i force genre 51 to become part of the query if the user chooses >> >> >> > at least one genre? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---
