使用 patchEntity 通过 cakephp 更新数据库记录时出现问题

Problem using patchEntity to update a database record with cakephp

我正在尝试将更新的记录保存到我的数据库中。我正在使用 bake 创建的代码,但新信息没有保存。我在我的代码中放置了 echo 语句以查看信息的价值是什么并且它显示了正确的信息,它只是不保存它。我很闲。

我尝试更改一些验证规则但没有成功。她是我的代码,里面有 echo 语句。

    public function edit() {
        echo $this->request->getData('id').  ' ';
        echo $this->request->getData('price') . ' ';

        $room = $this->Rooms->get($this->request->getData('id'), [
             'contain' => []
          ]);
        echo $room;

        if ($this->request->is('post')) {
            $room = $this->Rooms->patchEntity($room, $this->request->getData());
            echo $room;

            if ($this->Rooms->save($room)) {
                echo $room;
                exit();
                $this->Flash->success(__('The room has been saved.'));
                return $this->redirect(['action' => 'index']);
            }
            echo $room;
            exit();
            $this->Flash->error(__('The room could not be saved. Please, try again.'));
        }
        $this->set(compact('room'));
        return $this->redirect(['action' => 'index']);
    }

这是回显语句显示的内容:

1 
89.95 

{ "roomnumber": 101, "kingcount": 0, "queencount": 1, "fullcount": 0, "twincount": 0, "kitchenette": 0, "suite": 0, "rooms": 1, "floor": 1, "price": 69.95, "description": "This is a nice room with a single queen size bed and 55 inch flat screen television hung on the wall.", "id": 1 }{ "roomnumber": 101, "kingcount": 0, "queencount": 1, "fullcount": 0, "twincount": 0, "kitchenette": 0, "suite": 0, "rooms": 1, "floor": 1, "price": 89.95, "description": "This is a nice room with a single queen size bed and 55 inch flat screen television hung on the wall.", "id": 1 }{ "roomnumber": 101, "kingcount": 0, "queencount": 1, "fullcount": 0, "twincount": 0, "kitchenette": 0, "suite": 0, "rooms": 1, "floor": 1, "price": 89.95, "description": "This is a nice room with a single queen size bed and 55 inch flat screen television hung on the wall.", "id": 1 }

我希望当信息更改时将其保存到数据库中,但它只是 return 到包含旧信息的索引页面。

首先调试用cakephpdebug()或者corephpprint_r()函数,不要回显。阅读 patchEntity 调试输出,如果有任何错误消息,请在您的问题中 post。

https://book.cakephp.org/3.0/en/development/debugging.html

I am hoping for when the information changes it get saved to the database, but it just return to the index page with the old information.

清除缓存bin/cake cache clear_all

谢谢盐。我使用了 cakephp debug() 函数,发现了问题并且能够更正它。现在一切正常。