Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:04:31+00:00 2026-06-08T16:04:31+00:00

I’m try to develop a simple webservices in CakePHP 2.1. So, i first created

  • 0

I’m try to develop a simple webservices in CakePHP 2.1. So, i first created a DB table:

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 

Than I’ve created a simple Person model:

<?php
class Person extends AppModel {
    public $name = 'Person';
}

And respective controller:

<?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')
        ));
    }
}

and finally, in routes.php, I’ve mapped the proper roote:

<?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';

but when I try to reach ht_tp://localhost/cakephp/people.json I get:

<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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;autoRender&nbsp;=&nbsp;false;</span></code>
<code><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;View&nbsp;=&nbsp;$View;</span></code>
<span class="code-highlight"><code><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;response-&gt;body($View-&gt;render($view,&nbsp;$layout));</span></code></span></pre><pre id="cakeErr501541d86308c-context" class="cake-context" style="display: none;">$view = null
$layout = null
$serialize = array(
    (int) 0 =&gt; &#039;person&#039;
)
$data = array()
$key = &#039;person&#039;</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}

Where is the error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:04:32+00:00Added an answer on June 8, 2026 at 4:04 pm

    As you can see the response you’re getting is HTML. What it says (when you open it in a browser) is:

    Notice (8): Undefined index: person [CORE\Cake\View\JsonView.php, line 89]
    Code Context
    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
    {"person":null}
    

    Do you have any records in the database at all?
    Also what about the view for this method? It should be something like:

    // app/View/People/json/index.ctp
    <?php
    echo json_encode(compact('people'));
    

    Notice that the index.ctp file is located in the json sub-folder.
    Check the book out on JSON and XML views and comment if there are further problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.