dsvcqvp139098 2014-02-18 20:44
浏览 39
已采纳

FOS Elastica手动提供商服务注入问题

I am trying to create a manual provider to manually populate my FOS Elastica index to account for some complex joins. At the moment, I am just trying to get the provider to work even without the joins, and I am having trouble injecting the correct Elastica Type into my constructor for the provider. Here is the constructor of my provider:

// ...
class EmpPosDeptProvider implements ProviderInterface
{

    private $em;
    protected $type;

    public function __construct(Type $type, EntityManager $em)
    {
        $this->type = $type;
        $this->em = $em->getRepository('CcitEmployeesBundle:Position');
    }
// ...

and here is my services.yml file:

services:
    employees.search_provider.empPosDept:
        class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
        tags:
            - { name: fos_elastica.provider, index: employees, type: empPosDept }
        arguments:
            - %fos_elastica.type.class%
            - @doctrine.orm.entity_manager

When I try to execute php app/console fos:elastica:populate I am receiving the following error:

PHP Catchable fatal error:  Argument 1 passed to Ccit\EmployeesBundle\Search
\EmpPosDeptProvider::__construct() must be an instance of Elastica\Type, string given, 
called in /vagrant-nfs/employees/app/cache/dev/appDevDebugProjectContainer.php on line 736 
and defined in /vagrant-nfs/employees/src/Ccit/EmployeesBundle/Search
/EmpPosDeptProvider.php on line 23

Does anyone know what I need to give as a correct argument in my services.yml file? Or could the problem be something else entirely?

  • 写回答

2条回答 默认 最新

  • dqeonr8554 2014-02-18 20:49
    关注

    You're passing a string containing Ccit\EmployeesBundle\Search\EmpPosDeptProvider. You have to pass an instance of EmpPosDeptProvider, and it may be declared in your services.yml something like:

    services:
        fos_elastica.type:
            class: %fos_elastica.type.class%
    
        employees.search_provider.empPosDept:
            class: Ccit\EmployeesBundle\Search\EmpPosDeptProvider
            tags:
                - { name: fos_elastica.provider, index: employees, type: empPosDept }
            arguments:
                - @fos_elastica.type
                - @doctrine.orm.entity_manager
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了