Can';t通过CakePHP函数更新文件

Can';t通过CakePHP函数更新文件,cakephp,field,updating,Cakephp,Field,Updating,我想做一个函数,在点击按钮后,它会将某个任务的状态更改为“已完成” 首先,我在更新文件方面有问题 功能代码: public function change_status($id=null){ if($this->request->is('get')){ throw new MethodNotAllowedException(); } if($this->Task->change_status($id)){ $th

我想做一个函数,在点击按钮后,它会将某个任务的状态更改为“已完成”

首先,我在更新文件方面有问题

功能代码:

public function change_status($id=null){

    if($this->request->is('get')){
       throw new MethodNotAllowedException();
    }

    if($this->Task->change_status($id)){    

    $this->Task->id = $id;
    $this->Task->saveField('status', 'Finished');

    }

}
按钮代码

echo ('<i class="fa fa-times-circle"></i> '.$this->Form->postLink('ChangeStatus', array('action' => 'change_status', $task['Task']['ID']), array('confirm' => 'Are You want to change status of this task?')));
提前感谢您的帮助。

试试以下方法:

public function change_status($id=null){

    if($this->request->is('post')){
      $this->Task->id = $id;
      $this->Task->saveField('status', 'Finished');
    }else{
      throw new MethodNotAllowedException();
    }   
}
试试这个:

public function change_status($id=null){

    if($this->request->is('post')){
      $this->Task->id = $id;
      $this->Task->saveField('status', 'Finished');
    }else{
      throw new MethodNotAllowedException();
    }   
}

您正在引用
任务
模型中的
change\u status()
函数。你能展示一下代码吗?对我来说,如果你删除了
if
语句,你的函数应该在基本模型/字段更新调用中正确运行。你在
任务
模型中引用了
change\u status()
函数。你能展示一下代码吗?对我来说,如果您删除了
if
语句,那么您的函数应该在基本模型/字段更新调用中正确运行。