cakephp: notice 8:undefined index: id error
i'm getting Undefined index: id [APP\controllers\merry_parents_controller.php, line 31]Code
debug($this->data['MerryParent']);
echo 'id: '.$this->data['MerryParent']['id'];
MerryParentsController::login() - APP\controllers\merry_parents_controller.php, lin开发者_StackOverflow社区e 31
Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 204
Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 171
[main] - APP\webroot\index.php, line 83
My code:
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'];
for debug($this->data['MerryParent']), the record is displaying fine:
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
)
)
but when i try echo 'id: '.$this->data['MerryParent']['id'];
i'm getting notice 8: undefined index error. I have no idea on what is the problem. Can someone please help me?
Your array looks like this:
Array
(
[MerryParent] => Array
(
[MerryParent] => Array
(
[id] => 2
...
The id you're looking for is in $this->data['MerryParent']['MerryParent']['id']
. You probably want
$this->data = $this->Auth->user();
精彩评论