LoginSignup
6
6

More than 5 years have passed since last update.

【CakePHP】クライアントへJsonを出力する処理

Last updated at Posted at 2015-02-18

クライアント側にjsonを出力する処理。主にajaxを想定。
対象はcake2.1以上。

処理
$data = array(
  'status'=>1,
  'item'=>array(
    array('id'=>1,'name'=>'suzuki'),
    array('id'=>1,'name'=>'satou'),
  )
);

$this->viewClass = 'Json';
$this->set(compact('data'));

$this->set('_serialize','data');
出力されるデータ
{status: 1, item:[{id:1,name:"suzuki"},{id:1,name:"satou"}]}

クライアント側の処理:【jQuery】$.getJSON()

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6