pluess/doctrine-trx-bundle

此扩展包在控制器操作中提供容器管理的交易。

dev-master 2013-02-16 10:28 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:09:54 UTC


README

为控制器操作添加容器管理的交易,基于doctrine的持久化。

#使用方法

要让一个操作被交易覆盖,您只需要添加以下注解

<?php

use Pluess\DoctrineTrxBundle\Annotation\DoctrineTrx as ContainerTransaction;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Symfony\Component\HttpFoundation\Request;

/**
 * @Route("/my_route")
 */
class MyController extends Controller
{

    /**
     * @Route("/do-something", name = "do_something")
     * @ContainerTransaction
     */
    public function applyAction(Request $request)
    {
    	$em = $this->getDoctrine()->getManager()
    	
    	// Do whatever you want to do via doctrine.
    	// The annotation makes sure it's properly covered by a transaction.
    }
    
}

#安装

  1. 将其添加到您的 composer.json 文件中,并执行 composer update

    "pluess/doctrine-trx-bundle": "dev-master"
    
  2. 将其添加到您的 AppKernel.php 文件中

    new Pluess\DoctrineTrxBundle\PluessDoctrineTrxBundle()
    

#致谢

有很多我从他们那里学到了很多。此扩展包的主要学习来自于

  • Matthias Noback: 感谢您关于注解和事件监听器的优秀文章。这篇文章为这个扩展包打开了一扇门。
  • Johannes Schmitt: 感谢您展示了如何为symfony编写独立的函数测试。

#支持如果您在使用此扩展包时遇到问题,请随时提交问题。