0

this is my controller's edit_profile function:

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'));
    }

}

my problem is browser says, there is undefined index: restaurantid, in this line

$this->request->data['User']['restaurant_name'] = trim($_restaurants[$this->request->data['User']['restaurantid']]);

but i load my restaurant model, somebody help me to solve this problem.

Romano Zumbé
  • 7,893
  • 4
  • 33
  • 55
user3978043
  • 15
  • 1
  • 3

1 Answers1

0

"my problem is browser says, there is undefined index: restaurantid,"

Pretty clearly explains that there is no 'restaurantid' key in the $this->request->data['User'] array. debug() the array, and you'll see it's not there.

debug($this->request->data['User']);
Dave
  • 28,833
  • 23
  • 113
  • 183