0

いくつかの複雑な結合を考慮して、FOS Elastica インデックスを手動で設定する手動プロバイダーを作成しようとしています。現時点では、結合がなくてもプロバイダーを機能させようとしていますが、プロバイダーのコンストラクターに正しい Elastica Type を挿入するのに問題があります。これが私のプロバイダーのコンストラクターです。

// ...
class EmpPosDeptProvider implements ProviderInterface
{

    private $em;
    protected $type;

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

ここに私のservices.ymlファイルがあります:

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

実行しようとするphp app/console fos:elastica:populateと、次のエラーが表示されます。

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

services.yml ファイルで正しい引数として何を指定する必要があるか知っている人はいますか? それとも、問題はまったく別のものでしょうか?

4

2 に答える 2

0

どうやら、参照している型への明示的なパスを提供する必要がありました。次の行が機能しました:

@fos_elastica.index.employees.employeePositionDepartment

config.yml ファイルに次のものが含まれていることを考えると、これは理にかなっています。

fos_elastica:
clients:
    default: { host: localhost, port: 9200 }
indexes:
    employees:
        client: default
        types:
            employeePositionDepartment:
                mappings:
                    id: { type: integer }
                    title: { type: string }
                    startDate: { type: date, format: date_time_no_millis }
                    endDate: { type: date, format: date_time_no_millis }
                    supervisor: { type: integer }

このかなり基本的な質問で私を助けることを考えていた人に感謝します.

于 2014-02-18T20:51:14.110 に答える