CakePHP2.1で簡単なWebサービスを開発しようとしています。それで、私は最初にDBテーブルを作成しました:
CREATE TABLE IF NOT EXISTS `people` (
`id` char(36) COLLATE utf8_bin NOT NULL,
`first_name` varchar(100) COLLATE utf8_bin DEFAULT NULL,
`last_name` varchar(100) COLLATE utf8_bin NOT NULL,
`home_address` varchar(100) COLLATE utf8_bin DEFAULT NULL,
`job_address` varchar(100) COLLATE utf8_bin DEFAULT NULL,
`phone` varchar(20) COLLATE utf8_bin DEFAULT NULL,
`fax` varchar(20) COLLATE utf8_bin DEFAULT NULL,
`mail` varchar(100) COLLATE utf8_bin DEFAULT NULL,
`birth_date` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin
単純なPersonモデルを作成したよりも:
<?php
class Person extends AppModel {
public $name = 'Person';
}
そしてそれぞれのコントローラー:
<?php
class PeopleController extends AppController {
public $components = array('RequestHandler');
public function index() {
$people = $this->Person->find('all');
$this->set(array(
'people' => $people,
'_serialize' => array('person')
));
}
}
そして最後に、routes.phpで、適切なルートをマッピングしました。
<?php
Router::mapResources('people');
Router::parseExtensions('json');
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
しかし、ht_tp://localhost/cakephp/people.jsonに到達しようとすると、次のようになります。
<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr501541d86308c-trace').style.display = (document.getElementById('cakeErr501541d86308c-trace').style.display == 'none' ? '' : 'none');"><b>Notice</b> (8)</a>: Undefined index: person [<b>CORE\Cake\View\JsonView.php</b>, line <b>89</b>]<div id="cakeErr501541d86308c-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr501541d86308c-code').style.display = (document.getElementById('cakeErr501541d86308c-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr501541d86308c-context').style.display = (document.getElementById('cakeErr501541d86308c-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr501541d86308c-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"> $this->autoRender = false;</span></code>
<code><span style="color: #000000"> $this->View = $View;</span></code>
<span class="code-highlight"><code><span style="color: #000000"> $this->response->body($View->render($view, $layout));</span></code></span></pre><pre id="cakeErr501541d86308c-context" class="cake-context" style="display: none;">$view = null
$layout = null
$serialize = array(
(int) 0 => 'person'
)
$data = array()
$key = 'person'</pre><pre class="stack-trace">JsonView::render() - CORE\Cake\View\JsonView.php, line 89
Controller::render() - CORE\Cake\Controller\Controller.php, line 957
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 193
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 161
[main] - APP\webroot\index.php, line 92</pre></div></pre>{"person":null}
エラーはどこにありますか?