Cakephp& #39;s的模型保存方法不起作用


cakephp's model save method doesnt work

嗨,当我想通过控制器的edit()方法保存对模型的更改时,发生以下错误:

Error: Call to a member function save() on a non-object
File: K:'xampp'xampp'htdocs'app'Controller'UsersController.php
Line: 39

这是方法:

    public function edit($id = null){
        $this->User->id = $id;
        if(!$this->User->exists()){
            throw new NotFoundException(__('Invalid user'));
        }
        if($this->request->is('post')){
            ###### line number 39 - Where error happens >>>> 
            if($this->Uesr->save($this->request->data)){
                $this->Session->setFlash(__('The user has been saved'));
                $this->redirect(array('action' => 'index'));
            }else{
                $this->Session->setFlash(__('The user could not be saved. Please, try again'));
            }
        }else{
            $this->request->data = $this->User->read(null, $id);
            unset($this->request->data['User']['password']);
        }
    }

但是当我在add()方法中调用这个对象时没有错误,这是add()方法的代码:

    public function add(){
        if($this->request->is('post')){
            $this->User->create();
            if($this->User->save($this->request->data)){
                $this->Session->setFlash(__('The user has been saved.'));
                $this->redirect(array('action' => 'index'));
            }else{
                $this->Session->setFlash(__('The user could not be saved. Please, try again'));
            }
        }
    }

在编辑操作中,控制器的名称有一个拼写错误。

使用:

$this->User->save($this->request->data)

代替:

$this->Uesr->save($this->request->data)