【问题标题】:Cakephp - Cannot commit transaction - rollback()Cakephp - 无法提交事务 - 回滚()
【发布时间】:2018-08-07 08:34:06
【问题描述】:

我有一个小问题。我有一个 Cakephp 3.6 项目。一切正常,但是当我想删除一个控制器中的记录时,会显示我的错误。

无法提交事务 - rollback() 已在嵌套事务中调用 Cake\Database\Exception\NestedTransactionRollbackException

Cake\ORM\Table->删除
APP/Controller\NewsController.php,第 131 行

这是我在 NewsController.php 中的 delete 操作

public function delete($id = null)
{
    $this->request->allowMethod(['post', 'delete']);
    $news = $this->News->get($id);
    if ($this->News->delete($news)) {
        $this->Flash->success(__('The news has been deleted.'));
    } else {
        $this->Flash->error(__('The news could not be deleted. Please, try again.'));
    }

    return $this->redirect(['action' => 'index']);
}

并且错误在 if ($this->News->delete($news)) {

上突出显示

我能做什么?

【问题讨论】:

    标签: php database cakephp transactions cakephp-3.x


    【解决方案1】:

    默认情况下,所有删除都发生在事务中。您如何禁用与atomic 的事务?

    喜欢的东西

    $this->News->delete($news, ['atomic' => false]);

    【讨论】:

    • 如果工作,请标记为接受答案,可以帮助像你一样有同样问题的其他人:)
    猜你喜欢
    • 2012-12-24
    • 2013-11-20
    • 2013-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多