On Oct 12, 1:56 pm, Christian <[email protected]> wrote:
> Hi,
>
> The application I'm building will just basically provide a serie of
> webservices that output the data in json format.... What I'm doing is
> I have an element which basically does this
>
> echo $javascript->object($json);
>
> Anyways the point is, I have to keep writing in every single
> controller
>
> $this->set('json', $myWebServiceOutput);
> $this->render('/elements/json_return');
>
> Seems like there should be a way to do this automatically... at least
> the $this->render call.... I am not sure if I should put the call
> somewhere in my AppController.... any help on this one will be
> appreciated.
>
> Christian
Christian, this is what I'm currently using to do what you describe
This code goes in the AppController
function afterFilter(){
if ($this->RequestHandler->isAjax()){
$data = array();
if (!empty($this->viewVars['ajaxData']) &&
is_array($this->viewVars
['ajaxData'])) {
$data = $this->viewVars['ajaxData'];
}else{
$data = array('status'=>500,'msg' => 'No data
output');
}
echo json_encode($data);
exit();
}
}
it makes use of RequestHandler and works pretty well for the task.
Regards
Adrián
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---