2016-07-23 16 views
0

与えられた教義\ ORM \ EntityRepositoryの[何か]インスタンスのインスタンスである必要があります。symfonyは私がサービスを作成しようとしています

<?php 

namespace AppBundle\Service; 

use AppBundle\Repository\GroupEntityRepositoryInterface; 
use AppBundle\Repository\GroupUserRepository; 
use AppBundle\Repository\GroupUserRepositoryInterface; 
use AppBundle\Entity\Group; 
use AppBundle\Repository\GroupRepository; 


class GroupUserService 
{ 
    private $groupRepository; 
    private $groupUserRepository; 



    /** 
    * @param GroupRepositoryInterface $groupRepository 
    * @param GroupUserRepositoryInterface $groupUserRepository 
    */ 
    public function __construct(GroupRepository $groupRepository /*, GroupUserRepositoryInterface $groupUserRepository*/) 
    { 
     $this->groupRepository = $groupRepository; 
     // $this->groupUserRepository = $groupUserRepository; 
    } 

    public function deleteGroup(Group $group) 
    { 
     $this->groupRepository->delete($group); 
    } 

    public function createGroup(Group $group) 
    { 
     $this->groupRepository->add($group); 
    } 
} 

そして、私はそのサービスにリポジトリを注入するために設定を書いた:

services: 
# service_name: 
#  class: AppBundle\Directory\ClassName 
#  arguments: ["@another_service_name", "plain_value", "%parameter_name%"] 

    group_repository: 
     class: AppBundle\Repository\GroupRepository 
     factory: ["@doctrine.orm.entity_manager", getRepository] 
     arguments: 
      - AppBundle\Entity\Group 

    group_user_repository: 
     class: AppBundle\Repository\GroupUserRepository 
     factory: ["@doctrine.orm.entity_manager", getRepository] 
     arguments: 
      - AppBundle\Entity\GroupUser 

    group_user_service: 
     class: AppBundle\Service\GroupUserService 
     arguments: ["@group_repository", "@group_user_repository"] 
     #arguments: 
     # - "@group_repository" 

私はエラーを取得する:

Catchable Fatal Error: Argument 1 passed to AppBundle\Service\GroupUserService::__construct() must be an instance of AppBundle\Repository\GroupRepository, instance of Doctrine\ORM\EntityRepository given, called in E:\other\dropbox\Dropbox\programavimas\kodo pavyzdziai\htdocs\users_admin_demo\var\cache\dev\appDevDebugProjectContainer.php on line 1654 and defined

をすることができますなぜ私はGroupRepositoryを通過した場合EntityRepositoryインスタンスを取得するexplaing?それを修正する方法は?私は同様の質問を検索しようとしましたが、数時間後に結果が表示されません。

更新:

<?php 

namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity(repositoryClass="AppBundle\Repository\GroupRepository") 
* Group 
*/ 
class Group 
{ 
    /** 
    * @var string 
    */ 
    private $name; 

    /** 
    * @var integer 
    */ 
    private $id; 


    /** 
    * Set name 
    * 
    * @param string $name 
    * 
    * @return Group 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 
} 

Group.orm.xml:

<?xml version="1.0" encoding="utf-8"?> 
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> 
    <entity name="AppBundle\Entity\Group" table="`group`"> 
    <unique-constraints> 
     <unique-constraint name="UNIQ_6DC044C55E237E06" columns="name"/> 
    </unique-constraints> 
    <id name="id" type="integer" column="id"> 
     <generator strategy="IDENTITY"/> 
    </id> 
    <field name="name" type="string" column="name" length="255" nullable="false"> 
     <options> 
     <option name="fixed"/> 
     </options> 
    </field> 
    </entity> 
</doctrine-mapping> 

答えて

6

使用AppBundle\Entity\GroupのためのレポジトリとしてAppBundle\Repository\GroupRepositoryを定義

@ORM\Entity(repositoryClass="AppBundle\Repository\GroupRepository") 

XML

<entity 
    name="AppBundle\Entity\Group" 
    repository-class="AppBundle\Repository\GroupRepository"> 
</entity> 
+0

このコードはどこに貼り付けますか?ここでは、http://symfony.com/doc/current/book/doctrine.html#custom-repository-classesがエンティティクラス名の上にあることがわかりました。しかし何も変わりません。クリアされたキャッシュ。 –

+0

グループエンティティコード –

+0

更新された質問を表示してください。たぶん、これは何とかxmlで記述されるべきで、xmlをconfigに使用するのでアノテーションではないでしょうか? –

関連する問題