提问人:vaanipala 提问时间:9/26/2011 更新时间:9/26/2011 访问量:4160
Cakephp: 注意 8:undefined index: id 错误
cakephp: notice 8:undefined index: id error
问:
我得到未定义的索引:id [APP\controllers\merry_parents_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
我的代码:
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'];
对于 debug($this->data['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赞
JJJ
9/26/2011
#1
您的数组如下所示:
Array
(
[MerryParent] => Array
(
[MerryParent] => Array
(
[id] => 2
...
您要查找的 ID 位于 中。你可能想要$this->data['MerryParent']['MerryParent']['id']
$this->data = $this->Auth->user();
上一个:错误通知未定义索引
评论