On Mon, Mar 23, 2009 at 9:10 AM, cpeele <[email protected]> wrote:
>
>        function add()
>        {
>                if (!empty($this->data)) {
>
>                        $this->data += array('User' => array('user_id' => 
> $this->Session-
>>read('User.user_id')));
>
>                        if ($this->Event->save($this->data)) {
>
>                                $this->Session->setFlash("A new event has been 
> added");
>                                $this->redirect('/events', null, true);
>                        }
>                }
>        }
> }

$this->data['Event']['user_id'] = $this->Session->read('User.id');

You're setting a foreign key in Event, so it should be in the Event
array and called user_id. But, in the session, you refer to the
User.id, not User.user_id.


>        function view($id)
>        {
>                $events = $this->Event->User->findById($id);
>                $this->set('events', $events);
>        }

Are you sure you want to do this? I'd think it would be better to pass
the Event ID or date or something else. Although, if you *really* want
to only be able to view an Event based on some User's ID, then just
find based on the foreign key:

'conditions' => array(
  'Event.user_id' => $id
)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to