You can also avoid having to use a hidden field in this instance,
anyway, because the user_id can be added to $this->data before you
call save() in your action.

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

if ($this->SomeModel->save())
{
    ...

On Sun, Apr 26, 2009 at 1:01 PM, brian <bally.z...@gmail.com> wrote:
> Keep in mind that baking creates *very* generic views. They often will
> require tweaking. You can simply replace the select list with a hidden
> field:
>
> echo $form->hidden('SomeModel.user_id', array('value' =>
> $session->read('Auth.User.id'));
>
> Or, instead of grabbing it from the session in the view, you could do
> this in your action:
>
> $this->set('user_id', $this->Session->read('Auth.User.id'));
>
> echo $form->hidden('SomeModel.user_id', array('value' => $user_id));
>
> On Sat, Apr 25, 2009 at 7:06 PM, Teedaddy <bretteegar...@gmail.com> wrote:
>>
>> Thanks for the response.
>>
>> The main thing I am trying to do is make sure my index.ctp, view.ctp,
>> and add.ctp pages only return and show the data for the current logged
>> in user.id.
>>
>> For instance, it is easy enough to work with related data to a
>> specific user after they are selected from the user view but if I want
>> to add new records to a related table, the Baked forms for add.ctp
>> show all the users in the users table in a pull down input field. I
>> deally this would be a hidden input of just the user.id from the
>> view.ctp. I want to make sure any new rows added are automatically
>> assigned to the specific user, once they are logged in. This seems
>> like it should be simple, but everything I try does not work.
>>
>> On Apr 23, 7:58 pm, brian <bally.z...@gmail.com> wrote:
>>> On Thu, Apr 23, 2009 at 11:17 AM, Teedaddy <bretteegar...@gmail.com> 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 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