The usual and unhelpful answer applies:
You will have to rearrange your array-data yourself if you need it in
that format.

I would take another look at the javascript-component you are using...
because I can't really figure out why it would require the data in
that format. Repeating the user-data for each group sounds strange.

So if you really want to rearrange the data I would prefer to do it in
the User Model. You could create a method called "getUsersForExtJS()"
or something and in that method you do the actual findAll and some
data-manipulation before returning the data to the controller.

I would not use afterFind in this case since I really think it is only
something you want to do for some specific JS-component and not every
time you find a user.




On Apr 9, 4:28 pm, inma <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have an User class and a PermissionGroup class. User has defined a
> hasAndBelongsToMany relation with PermissionGroup.
>
> If into database exists one user with two permission grups assigned,
> when I run this code:
>
> $userA = $this->User->findAll($sort, $limit, $page); //gets all the
> User records and sorts them.
>
> It returns an array that contains the user data array and the
> permission groups array:
>
> Array(
>   [User] => Array(
>                     here the user data
>               )
>   [PermissionGroup] => Array(
>                    [0] => Array(
>                here the FIRST permission data
>                           )
>                    [1] => Array(
>                              here the SECOND permission data
>                           )
>                 )
> )
>
> I turn it into a json format because I use ExtJS library into the
> views:
>
> {"total":1, "users":[{"User":{ here the user data },
> "PermissionGroup":
> [{ here the first permission data }, { here the second permission
> data }]}]}
>
> But I need an array for each permission group assigned to user. Like
> this:
>
> Array(
>   [User] => Array(
>                                here the user data
>               )
>   [PermissionGroup] => Array(
>                    [0] => Array(
>                here the FIRST permission data
>                           )
>                 )
> ),
> Array(
>   [User] => Array(
>                                here the user data
>               )
>   [PermissionGroup] => Array(
>                    [0] => Array(
>                here the SECOND permission data
>                           )
>                 )
> )
>
> Turned into json format:
>
> {"total":2,
> "users":[{"User":{ here the user data }, "PermissionGroup":{ here the
> FIRST permission data }},
> {"User":{ here the user data }, "PermissionGroup":{ here the SECOND
> permission data }}
> ]}
>
> ¿How can I do it?
>
> Thanks in advance!
>
> P.S: ( I have asked this questions a few hours ago, but it doesn't
> appear. So I have repeated it...)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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