如何在不传递的情况下在存储库类中获取容器对象 参数β
答案 0 :(得分:5)
您将获得容器对象,如下所示:
// include files to get container
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
class ClassNameRepository extends EntityRepository implements ContainerAwareInterface
{
/**
* @var ContainerInterface
*
* @author Ashok Chitroda <ashok.chitroda@gmail.com>
*/
private $container;
public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}
}
由于
Ashok Chitroda