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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler