2011-09-26 77 views
0

我得到未定義指數:ID [APP \控制器\ merry_parents_controller.php,線31]代碼cakephp的:通知8:未定義指數: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 

我的代碼:

merry_parents_controller。 PHP

if ($this->Auth->user()){ 
      //debug($this->Auth->user()); 
      $this->data['MerryParent']=$this->Auth->user(); 
      debug($this->data['MerryParent']); 
      echo 'id: '.$this->data['MerryParent']['id']; 

調試($這 - >數據[ 'MerryParent']),該記錄被顯示精細:

Array 
(
    [MerryParent] => Array 
    (
    [id] => 2 
    [initial] => Ms 
    [username] => hong 
    [email] => [email protected] 
    [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 
    ) 
) 

但是當我嘗試 echo'id:'。$ this-> data ['MerryParent'] ['id'];

我收到通知8:未定義的索引錯誤。我不知道有什麼問題。有人可以幫幫我嗎?

回答

2

你的陣列看起來像這樣:

Array 
(
    [MerryParent] => Array 
    (
     [MerryParent] => Array 
     (
      [id] => 2 
      ... 

你要找的id爲$this->data['MerryParent']['MerryParent']['id']。你可能想要

$this->data = $this->Auth->user(); 
+0

是的,你絕對正確。這工作。謝謝! – vaanipala