Cakephp 未知方法“;saveAll";

Cakephp 未知方法“;saveAll";,cakephp,Cakephp,几年后,我刚刚完成了我的第一个测试项目。。我很困惑 public function add() { $post = $this->Posts->newEntity(); if ($this->request->is('post')) { $post = $this->Posts->patchEntity($post, $this->request->getData()); if ($this->

几年后,我刚刚完成了我的第一个测试项目。。我很困惑

public function add()
{
    $post = $this->Posts->newEntity();
    if ($this->request->is('post')) {
        $post = $this->Posts->patchEntity($post, $this->request->getData());
        if ($this->Posts->saveAll($post)) {
            $this->Flash->success(__('The post has been saved.'));

            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('The post could not be saved. Please, try again.'));
    }
    $parentPosts = $this->Posts->ParentPosts->find('list', ['limit' => 200]);
    $this->set(compact('post', 'parentPosts'));
    $this->set('_serialize', ['post']);
}
在我提交表格后,我得到

未知方法“saveAll”

BadMethodCallException

我所改变的只是

$this->Posts->save($post) 
(这很好)到


为什么这里不知道这种方法?与saveAssociated等类似。谢谢

从CakePHP 3.2.8版可以一次保存多条记录,但要使用的函数是$this->Posts->saveMany($post)。您可以使用cakephp文档中提到的代码

$this->Posts->saveAll($post)