Try:

echo '{"totalCount":"11", "Contacts":',$javascript->object(Set::extract($data, 
'{n}.Contact'),false),'}};

-- Felix
--------------------------

http://www.thinkingphp.org
http://www.fg-webdesign.de


das88 wrote:
> I'm using cake with the extjs javascript library. JSON often seems the
> glue to put different libraries together. It seems, though, the JSON
> output form cake has more depth than that expected by extjs.
>
> For example,
>
> My controller looks like
>               $data=$this->Contact->findAll(
>                               null,
>                               array('id','firstName','lastName')
>               );
>
>               $this->set('data',$data);
>
> My view converts the data array to JSON
> echo '{"totalCount":"11", "Contacts":',$javascript-
>   
>> object($data,false),'}};
>>     
>
> I get something like
> {"totalCount":"2", "Contacts":[
>       {"Contact":{"id":100002, "firstName":"first1", "lastName":"last1"}},
>       {"Contact":{"id":100003, "firstName":"first2", "lastName":"last2"}}
> ]}
>
> What extjs expects, though, is something like
> {"totalCount":"2", "Contacts":[
>       {"id":100002, "firstName":"first1", "lastName":"last1"},
>       {"id":100003, "firstName":"first2", "lastName":"last2"}
> ]}
>
> I make the two look the same by running a depth reduction routine in
> my controller
>               foreach($data as $row) {
>                       $dataR[]=$row['Contact'];
>               }
>
> My question is, is there a better way to go about this. Have the extra
> loop in my controller seems really inefficient. Is there a better way
> to pull the data than what I am doing? Am I missing a parameter on
> findall or should I be using a different method?
>
> It seems to me that the JSON structure used by extjs is superior to
> cake's. Less depth is easier to work with and it is smaller.
>
>
> >
>
>   

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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