Thanks for helping I already have the json.ctp set up I have this in
my controller - $this->response->number = 0;
And this is my json.ctp
<?php
if(isset($response->string)) {
echo $response->string;
} elseif(isset($response->number)) {
// echo json_encode(array($response->number));
echo $response->number;
//echo json_encode($response);
//echo json_encode(array($response->number));
//echo json_encode(array('error' => 'Sorry there is no data for your
current query'));
} else {
if(!empty($response)) {
echo json_encode(array('error' => 'Sorry there is no data for your
current query'));
} else {
echo json_encode(array('error' => 'Sorry there is no data for your
current query'));
}
//
}
?>
and echo $response->number;
Returns empty when it should show 0
Thanks,
Almog
On Feb 3, 6:15 pm, thatsgreat2345 <thatsgreat2...@gmail.com> wrote:
> You could just do a quick condition
> ( (empty($response->number)) ? 0 : json_encode($response->number))
>
> This makes it seems like you are echoing it out from the controller.
> To keep MVC form I have a function in my AppController(app_controller
> on 1.3) which I can call with $this->json(arrayhere)
> It encodes to json, and then uses json.ctp element as the layout.
>
> On Feb 3, 4:23 am, Almog <al...@almogdesign.net> wrote:
>
>
>
>
>
>
>
> > I can use some help have a simple bug but figure out what to do.
>
> > I have echo json_encode($response);
>
> > which works fine unless the response is "0" and then I get an empty
> > "responseVars:"
>
> > If I do echo json_encode($response ->number);
> > I get responseVars: {"number":0} also incorrect it should just return
> > "0"
>
> > Any ideas what I'm doing wrong?
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
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
No comments:
Post a Comment