cakephp:注意8:未定义索引:id错误

cakephp:注意8:未定义索引:id错误,cakephp,notice,undefined-index,Cakephp,Notice,Undefined Index,我得到了未定义的索引:id[APP\controllers\merry\u parents\u controller.php,第31行]代码 debug($this->data['MerryParent']); echo 'id: '.$this->data['MerryParent']['id']; MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 3

我得到了未定义的索引:id[APP\controllers\merry\u parents\u controller.php,第31行]代码

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
我的代码:

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
merry_parents_controller.php

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
if ($this->Auth->user()){
            //debug($this->Auth->user());
            $this->data['MerryParent']=$this->Auth->user();
            debug($this->data['MerryParent']);
            echo 'id: '.$this->data['MerryParent']['id'];
对于调试($this->data['MerryParent']),记录显示良好:

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
Array
 (
  [MerryParent] => Array
    (
    [id] => 2
    [initial] => Ms
    [username] => hong
    [email] => hong7@yahoo.com
    [password2] => hong7
    [landline] => 
    [mobile] => 293472389472
    [address] => dsaflkjasdlfk
    [state_id] => 5
    [city_id] => 62
    [postal_code] => 825729
    [created] => 2011-08-02 10:29:59
    [modified] => 2011-09-26 06:42:27
     )
)
但是当我尝试的时候 回显'id:'。$this->data['MerryParent']['id']

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83

我收到通知8:未定义的索引错误。我不知道是什么问题。有人能帮我吗?

您的阵列如下所示:

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
Array
(
    [MerryParent] => Array
    (
        [MerryParent] => Array
        (
            [id] => 2
            ...
您要查找的id位于
$this->data['MerryParent']['MerryParent']['id']
中。你可能想要

debug($this->data['MerryParent']);
    echo 'id: '.$this->data['MerryParent']['id'];

 MerryParentsController::login() - APP\controllers\merry_parents_controller.php, line 31
 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
 [main] - APP\webroot\index.php, line 83
$this->data = $this->Auth->user();