Message from discussion
JSON response!
Received: by 10.42.89.20 with SMTP id e20mr7897679icm.3.1334602315484;
Mon, 16 Apr 2012 11:51:55 -0700 (PDT)
X-BeenThere: cake-php@googlegroups.com
Received: by 10.231.71.151 with SMTP id h23ls8407607ibj.6.gmail; Mon, 16 Apr
2012 11:51:20 -0700 (PDT)
Received: by 10.68.218.103 with SMTP id pf7mr2510881pbc.11.1334602280032;
Mon, 16 Apr 2012 11:51:20 -0700 (PDT)
Date: Mon, 16 Apr 2012 11:51:19 -0700 (PDT)
From: Rob <rcole...@mailforce.net>
To: cake-php@googlegroups.com
Cc: Serkan Sipahi <serkan.sip...@yahoo.de>
Message-ID: <945181.425.1334602279394.JavaMail.geo-discussion-forums@ynid24>
In-Reply-To: <1334414331.8075.YahooMailNeo@web29019.mail.ird.yahoo.com>
References: <1334408187.32858.YahooMailNeo@web29003.mail.ird.yahoo.com> <26780508.982.1334411811748.JavaMail.geo-discussion-forums@vbxy18>
<1334414331.8075.YahooMailNeo@web29019.mail.ird.yahoo.com>
Subject: Re: JSON response!
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_423_22010417.1334602279392"
------=_Part_423_22010417.1334602279392
Content-Type: multipart/alternative;
boundary="----=_Part_424_25021636.1334602279392"
------=_Part_424_25021636.1334602279392
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
It is not possible to send both a HTML and a JSON response for the same
request. However, you can detect the type of request and respond with HTML
or JSON accordingly. For example:
public function index()
{
$this->set('test', array(
'Hallo World!',
));
if($this->RequestHandler->accepts('json'))
$this->set('_serialize', array('test'));
}
On Saturday, April 14, 2012 10:38:51 AM UTC-4, Sipatshi wrote:
>
> hi,
>
> i remove Router::parseExtensions('json');
>
> My wish is to do something like this:
>
> <?php
> class SomeController extends AppController {
>
> public $components = array(
> 'RequestHandler'
> );
>
> public function index(){
>
> /********
> json response
> /********
> $this->RequestHandler->setContent('json', 'application/json' );
> $this->set('test', array(
> 'Hallo World!',
> ));
> $this->set('_serialize', array('test'));
>
> /********
> html response
> /********
> $this->RequestHandler->setContent('html', '**text/html, */*'
> );
> $this->set('test_2', array(
> 'Hallo World 2',
> ));
> }
> }
>
> is that possible?
>
> ------------------------------
> *Von:* stork <lubomir.st...@gmail.com>
> *An:* cake-php@googlegroups.com
> *CC:* Serkan Sipahi <serkan.sip...@yahoo.de>
> *Gesendet:* 15:56 Samstag, 14.April 2012
> *Betreff:* Re: JSON response!
>
> If you called Router::parseExtensions() in routes.php, you don't need to
> call $this->RequestHandler->
> setContent() manually - as long as requested URI does have .json extension
> at the end or ajax request was called with proper dataType/accept request
> header.
> --
> 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
>
>
>
------=_Part_424_25021636.1334602279392
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
It is not possible to send both a HTML and a JSON response for the same req=
uest. However, you can detect the type of request and respond with HT=
ML or JSON accordingly. For example:<div><br></div><div><div><div><fo=
nt color=3D"#000000" face=3D"'courier new', monospace">public function inde=
x()</font></div><div><font color=3D"#000000" face=3D"'courier new', monospa=
ce">{</font></div><div><font color=3D"#000000" face=3D"'courier new', monos=
pace"> $this->set('test', array(</font></div><div><font col=
or=3D"#000000" face=3D"'courier new', monospace">  =
; 'Hallo World!',</font></div><div><font color=3D"#000000" fa=
ce=3D"'courier new', monospace"> ));</font></div><div><font co=
lor=3D"#000000" face=3D"'courier new', monospace"> &nbs=
p; </font></div><div><font color=3D"#000000" face=3D"'courier new', mo=
nospace"> if($this->RequestHandler->accepts('json'))</fo=
nt></div><div><font color=3D"#000000" face=3D"'courier new', monospace">&nb=
sp; $this->set('_serialize', array('test'));</font>=
</div><div><font color=3D"#000000" face=3D"'courier new', monospace">}</fon=
t></div></div><br>On Saturday, April 14, 2012 10:38:51 AM UTC-4, Sipatshi w=
rote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div><div style=3D"color:=
#000;background-color:#fff;font-family:arial,helvetica,sans-serif;font-size=
:10pt"><div><span>hi,</span></div><div><br><span></span></div><div><span>i =
remove </span>Router::parseExtensions('json'<wbr>);</div><div><br></div><di=
v>My wish is to do something like this:<br></div><div><br></div><div><?p=
hp<br> class SomeController extends AppController {<br>&n=
bsp; <br> =
public $components =3D
array(<br> &nbs=
p; 'RequestHandler'<br> );<br>&nb=
sp; <br> &=
nbsp; public function index(){</div><div><br></div><div><span> &=
nbsp; </span><span> </span><span> =
/********</span></div><div><span>  =
; </span><span lang=3D"en"><span>json</span> <span>=
response</span></span></div><div> =
/********<br><span></span></div><div><span></span>
$this-&g=
t;RequestHandler-><wbr>setContent('json', 'application/json' );<br>
$this-&g=
t;set('test', array(<br>
&nb=
sp; 'Hallo World!',<br>
));<br>
$this-&g=
t;set('_serialize', array('test'));</div><div><br></div><div><span> &n=
bsp; </span><span> </span><span> =
/********</span></div>
<div><span> &nbs=
p; html</span><span lang=3D"en"><span></span> <span>response</span></span><=
/div>
<div> /**=
******<br>
<span></span></div>
<div><span></span>
$this-&g=
t;RequestHandler-><wbr>setContent('html', '<strong></strong>text/html, *=
/*' );<br>
$this-&g=
t;set('test_2', array(<br>
&nb=
sp; 'Hallo World 2',<br>
));<br>&=
nbsp; }<br> } <br></d=
iv><div><br></div><div> is that possible?<br></div><div><=
br></div> <div style=3D"font-family:arial,helvetica,sans-serif;font-size:1=
0pt"> <div style=3D"font-family:times new roman,new york,times,serif;font-s=
ize:12pt"> <div dir=3D"ltr"> <font face=3D"Arial" size=3D"2"> <hr size=3D"1=
"> <b><span style=3D"font-weight:bold">Von:</span></b> stork <<a href=
=3D"mailto:lubomir.st...@gmail.com" target=3D"_blank">lubomir.st...@gmail.c=
om</a>><br> <b><span style=3D"font-weight:bold">An:</span></b> <a href=
=3D"mailto:cake-php@googlegroups.com" target=3D"_blank">cake-php@googlegrou=
ps.com</a> <br><b><span style=3D"font-weight:bold">CC:</span></b> Serkan Si=
pahi <<a href=3D"mailto:serkan.sip...@yahoo.de" target=3D"_blank">serkan=
.sip...@yahoo.de</a>> <br> <b><span style=3D"font-weight:bold">Gesendet:=
</span></b> 15:56 Samstag, 14.April 2012<br> <b><span style=3D"font-weight:=
bold">Betreff:</span></b> Re: JSON response!<br> </font> </div> <br><div>If=
you called
Router::parseExtensions() in routes.php, you don't need to call $this->=
RequestHandler-><div> setContent() manually - as long as requested URI d=
oes have .json extension at the end or ajax request was called with proper =
dataType/accept request header.<br></div>
-- <br>
Our newest site for the community: CakePHP Video Tutorials <a rel=3D"nofoll=
ow" href=3D"http://tv.cakephp.org" target=3D"_blank">http://tv.cakephp.org<=
/a> <br>
Check out the new CakePHP Questions site <a rel=3D"nofollow" href=3D"http:/=
/ask.cakephp.org" target=3D"_blank">http://ask.cakephp.org</a> and help oth=
ers with their CakePHP related questions.<br>
<br>
<br>
To unsubscribe from this group, send email to<br>
<a href=3D"mailto:cake-php%2Bunsubscribe@googlegroups.com" target=3D"_blank=
">cake-php+unsubscribe@<wbr>googlegroups.com</a> For more options, visit th=
is group at <a rel=3D"nofollow" href=3D"http://groups.google.com/group/cake=
-php" target=3D"_blank">http://groups.google.com/<wbr>group/cake-php</a><br=
>
</div><br><br> </div> </div> </div></div></blockquote></div>
------=_Part_424_25021636.1334602279392--
------=_Part_423_22010417.1334602279392--