Saturday, January 3, 2009

Re: storing user_ids

On Sat, Jan 3, 2009 at 9:02 PM, ymadh <admin@dogtrainersearch.com> wrote:
>
> Each record of the associated tables. So if a client is created under
> a logged in user, I want it to autopopulate the db with user_id which
> is in the session. That way each user only sees their clients..make
> sense? My client table would have client info, and of course a user_id
> field.
>
> I didn't link the models ... Would that create extra overhead on every
> page that needs that user_id field??

If you have a user_id column in a model's table, then you should
associated it with the User model. That way, you'll have to do very
little to store it.

In your view, you can add a hidden field:

echo $form->hidden('User.id', array('value' => $session->read('User.id')));

That will give your controller a $data array something along these lines:

array(
'YourModel' => array(
'some field' => 'some value',
...
),
'User' => array(
'id' => 42
)
)

That presupposes that only logged-in users will use that form. And,
again, that this model is properly associated with User.

As for overhead, you can use the ContainableBehavior to adjust what
Cake queries the DB for.

--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: