Hi,
i read the manuel.
1.) Enable the json and or xml extensions with Router::parseExtensions(). This
will enable Router to handle
mulitple extensions.
Router::parseExtensions('htm','json');
<?php
class SomeController extends AppController {
/**************
2.) Add the RequestHandlerComponent to your controller’s list of
components. This will enable automatic view class switching on content
types.
**************/
public $components =
array(
'RequestHandler'
);
public function index(){
/*****************
3.) After adding Router::parseExtensions('json'); to your routes
file,
CakePHP
will automatically switch view classes when a request is done with the .json
extension,
or the Accept header is application/json.
******************/
$this->RequestHandler->setContent('json', 'application/json' );
$this->set('test', array(
'Hallo World!',
));
/***********
4.) Using data views with the serialize key(not by Using a data view
with view files)
************/
$this->set('_serialize', array('test'));
}
}
P.S. In addition to the html document, i want to send json data, too!
________________________________
Von: Tilen Majerle <[email protected]>
An: [email protected]
Gesendet: 14:59 Samstag, 14.April 2012
Betreff: Re: JSON response!
you have to set view to json
public $viewClass = 'Json'; something like that :)
read manual again :D
--
Lep pozdrav, Tilen Majerle
http://majerle.eu
2012/4/14 Serkan Sipahi <[email protected]>
Hi all,
>
>
>I want to create a JSON response! Scripting my file according to the manuel:
>http://book.cakephp.org/2.0/en/views/json-and-xml-views.html
>It does not work. I get no response from the server! what am I doing wrong?
>
>
><?php
> class SomeController extends AppController {
>
> public $components =
array(
> 'RequestHandler'
> );
>
> public function index(){
> $this->RequestHandler->setContent('json', 'application/json' );
> $this->set('test', array(
> 'Hallo World!',
> ));
> $this->set('_serialize', array('test'));
> }
> } --
>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
>[email protected] For more options, visit this group at
>http://groups.google.com/group/cake-php
>
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php
--
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
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php