这是我的控制器的edit_profile函数:
public function editProfile()
{
$user = $this->UserAuth->getUser();
$userId = $user['User']['id'];
$this->loadModel('Restaurant');
$_restaurants = $this->Restaurant->find('list');
$this->set('restaurants', $_restaurants);
if (!empty($userId)) {
$userGroups = $this->UserGroup->getGroups();
$this->set('userGroups', $userGroups);
if ($this->request->isPut()) {
$this->request->data['User']['restaurant_name'] = trim($_restaurants[$this->request->data['User']['restaurantid']]);
$this->User->set($this->data);
if ($this->User->RegisterValidate()) {
if (empty($this->request->data['User']['password'])) {
unset($this->request->data['User']['password']);
} else {
$this->request->data['User']['password'] = $this->UserAuth->makePassword($this->request->data['User']['password']);
}
$this->User->create();
$this->User->save($this->request->data, false);
$this->Session->setFlash(__('The user is successfully updated'));
$this->redirect(array ('plugin' => false, 'controller' => 'orders', 'action' => 'orderList'));
}
} else {
$user = $this->User->read(null, $userId);
$this->request->data = null;
if (!empty($user)) {
$user['User']['password'] = '';
$this->request->data = $user;
}
}
} else {
$this->redirect(array ('plugin' => false, 'controller' => 'orders', 'action' => 'orderList'));
}
}
我的问题是浏览器说,有未定义的索引:restaurantid,在这一行
$this->request->data['User']['restaurant_name'] = trim($_restaurants[$this->request->data['User']['restaurantid']]);
但我加载了我的餐厅模型,有人帮我解决了这个问题。
答案 0 :(得分:0)
"我的问题是浏览器说,有未定义的索引:restaurantid,"
非常明确地解释说,没有' restaurantid' $this->request->data['User']
数组中的键。 debug()
数组,你会发现它不存在。
debug($this->request->data['User']);