Cakephp3输入为空进行编辑


Cakephp 3 inputs empty for edit

所以我正在尝试创建一个编辑功能,当我按下编辑按钮时,它似乎会将我重定向到具有正确id的编辑页面,但所有输入都是空的。。。。有什么想法吗?

public function edit($id=null) {
   $user =$this->Users->get($id); 
    if ( !$this->Users->exists($user) ) {
        throw new NotFoundException( __( 'Invalid user' ) );
    }
    if ( $this->request->is( 'post' ) || $this->request->is( 'put' ) ) {
         $user = $this->Users->patchEntity($user, $this->request->data);
         $query = $this->Users->find( 'all', array( 'conditions' => array( 'id' => $id) ));
         $aros = $query->first()->toArray();
        $save = $this->Users->save( $this->request->data );
        if ($save) {
            $this->Flash->success( 'The user has been saved');
        } else {
            $this->Flash->error( 'The user could not be saved. Please, try again.');
        }}

您没有粘贴所有需要的代码,所以这里有两个猜测:

  1. 您没有将实体设置为视图
  2. 如果设置了它,还需要将它传递给表单create()
  3. 在save()之前,您也缺少一个patchEntity()调用
  4. 您需要将一个实体传递给save()

我建议你在book.cakephp.org上做基础教程,根据粘贴的代码和你想做的事情,你似乎根本不知道它是如何工作的。