【发布时间】:2017-11-21 10:50:36
【问题描述】:
我想要实现的是调用学说 ini TwigExtension,我从 google 和 stackoverflow 获得了一些代码,如下所示:
service.yml
twig.extension:
class: AppBundle\Twig\AppExtension
arguments:
doctrine : '@doctrine'
tags:
- { name: twig.extension }
AppBundle\Twig\AppEtension.php
<?php
namespace AppBundle\Twig;
use Symfony\Bridge\Doctrine\RegistryInterface;
class AppExtension extends \Twig_Extension
{
protected $doctrine;
public function __construct(RegistryInterface $doctrine)
{
$this->doctrine = $doctrine;
}
}
我已按照来源的所有说明进行操作,但我仍然遇到错误,无法在这里调用教义或使用 entitymanager 进行操作。
这是我的错误:
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Invalid key "doctrine" found in arguments of method "__construct()" for service "twig.extension": only integer or $named arguments are allowed.
如何解决?
【问题讨论】:
-
试试@doctrine.orm.entity_manager
-
@Jory 下面的回答是正确的解决方案。问题是您使用的是旧版本的 Symfony,但试图遵循最新的文档。在服务容器文档页面右上角选择正确的 Symfony 版本,看看区别。
标签: php symfony doctrine-orm doctrine