Hi mate,
I suggest using $user['User'] in all situations. I know it looks 
redundant at first, to add the extra level when you just know you will 
work with a single model data only.
The point though, is that it makes the app as a whole so much easier to 
read when you use the same notation everywhere. That's the power of 
convention that CakePHP uses so often.

If you have to stick with the duality however, I suggest this code:
if (isset($user['User'])) {
   $data = &$user['User'];
} else {
   $data = &$user;
}

Then use $data['id'] etc.

I hope it helps.

Petr
http://blog.pepa.info/


Dne 16.11.2008 15:45, validkeys napsal(a):
> Hey Guys,
> 
> Sometime I will pass a function an array structured like this: $user
> ['User']['id'] (the array contains a bunch of other values under the
> User key). Other times I will pass the same function an array but with
> out the key ($user['id']).
> 
> So I use this if statement to get the values:
> 
> // @var is an array of user data
> 
> function test_for_groups($user) {
> 
>               if (isset($user['User'])){
>                       $user_id = $user['User']['id'];
>                       $company_id = $user['User']['company_id'];
>               }else{
>                       $user_id = $user['id'];
>                       $company_id = $user['company_id'];
>               }
> 
> 
> What is a better way to do this?


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