2017-07-11 1 views
0

私はCakePhpを学び始めました。 http://localhost:8888/todolist/entries/index.json URLを使ってブラウザを開くたびに、私は安らかなアプリケーションを作成しようとしています.Jsonレスポンスは得られません。ケーキPHP安らかなインデックスメソッドは、空の応答を返します

<?php 
    App::uses('AppController', 'Controller'); 
    /** 
    * Entries Controller 
    * 
    * @property Entry $Entry 
    * @property PaginatorComponent $Paginator 
    */ 
    class EntriesController extends AppController { 

     /** 
     * @var array 
     */ 
     public $helpers = array('Html', 'Form'); 

    /** 
    * Components 
    * 
    * @var array 
    */ 
     public $components = array('Paginator', 'RequestHandler'); 

    /** 
    * index method 
    * 
    * @return void 
    */ 
     public function index() { 
      $this->Entry->recursive = 0; 
      $this->set('entries', $this->Paginator->paginate()); 

      $this->autoRender = false; 
      $this->layout = false; 
     } 
} 

これは私のroutes.phpのです:

以下
Router::connect('/', array('controller' => 'entries', 'action' => 'index')); 
/** 
* ...and connect the rest of 'Pages' controller's URLs. 
*/ 
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); 

/** 
* Load all plugin routes. See the CakePlugin documentation on 
* how to customize the loading of plugin routes. 
*/ 
    CakePlugin::routes(); 

/** 
* Load the CakePHP default routes. Only remove this if you do not want to use 
* the built-in default routes. 
*/ 
    require CAKE . 'Config' . DS . 'routes.php'; 

Router::mapResources('entries'); 
Router::parseExtensions('json'); 

は放火犯からのスクリーンショットです。

Firebug Network screenshot

答えて

0

あなたは無効なレンダリングをしました:

ので、
$this->autoRender = false; 

あなたが空の応答を得るでしょう。レンダリングを無効にする必要がありません、RESTとJSON/XMLビュードキュメントで説明したようにシリアル化されたビューを使用します。

public function index() { 
    $this->Entry->recursive = 0; 
    $this->set('entries', $this->Paginator->paginate()); 
    $this->set('_serialize', 'entries'); // that's where the magic begins 
} 

も参照してください

関連する問題