On Thu, Apr 23, 2009 at 11:17 AM, Teedaddy <[email protected]> wrote:
>
> hello friends, I am VERY new to all the cakePHP methods, so, any help
> would be much appreciated.
>
> I have built my database tables and have Baked all Models,
> Controllers, and Views. Everything is working as expected with the
> relations and interaction with the db tables.
>
> I am now trying to customize the view, add, and edit functions. The
> main thing I need to do is make many of the views, User.id specific
> and can't for the life of me figure out the best way to do that.
Define "User.id specific". Do you mean that you need to save a user_id
foreign key with your data? Are you saving the user to a session when
logged in?
> Here is a sample of code of what I am trying to do. I just want the
> add form to grab the current User.id for saving to the database.
>
> function writer_add() {
> if (!empty($this->data)) {
> $this->Writer->create();
> if ($this->Writer->save($this->data)) {
> $this->Session->setFlash(__('The Writer has
> been saved', true));
> $this->redirect(array('action'=>'index'));
> } else {
> $this->Session->setFlash(__('The Writer could
> not be saved.
> Please, try again.', true));
> }
> }
> $users = $this->Writer->User->find('first', array('User' =>
> 'User.id'));
> $this->set(compact('users'));
> }
>
This makes no sense. If you want find a *specific* ('first') User,
then you need to put 'User.id' on the left side and pass a $user_id on
the right. Also, though it's not too big a deal, I guess your var
should be $user, not $users.
Anyway, if you save the User to the session when they log in, you
won't need to do a find() here. Maybe you should explain what it is
you're trying to do.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---