dongye3917
2017-11-21 10:50
浏览 87
已采纳

Symfony将doctrine添加到services.yml和自定义扩展

What I want achieve is call doctrine ini TwigExtension, I get some code from google and stackoverflow, like this :

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;
    }

}

I've followed all instruction from my source, but i still got error and cant call doctrine or do something with entitymanager here.

this is my error :

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.  

how to solve this?

图片转代码服务由CSDN问答提供 功能建议

我想要实现的是调用doctrine ini TwigExtension ,我从google获取了一些代码 stackoverflow,如下所示:

service.yml

  twig.extension:
 class:AppBundle \ Twig \ AppExtension 
 arguments:  
 doctrine:'@ doctrine'
 tags:
  -  {name:twig.extension} 
   
 
 

AppBundle \ Twig \ AppEtension.php

 &lt;?php 
 
namespace AppBundle \ Twig; 
 
use Symfony \ Bridge \ Doctrine \ RegistryInterface; 
 
class AppExtension extends \ Twig_Extension 
 {
 protected $ doctrine  ; 
 
公共函数__construct(RegistryInterface $ doctrine)
 {
 $ this-&gt; doctrine = $ doctrine; 
} 
 
} 
   
 
  

我已经遵循了我的来源的所有说明,但我仍然有错误,无法调用教条或在这里使用entitymanager做一些事情。

这是我的错误: \ ñ

 <代码>的Symfony \元器件\ DependencyInjection \异常\无效 ArgumentException] 
在服务“twig.extension”的方法“__construct()”的参数中找到无效的密钥“doctrine”:只允许整数或$ named参数。  
   
 
 

如何解决这个问题?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题