2016-05-31 53 views

回答

1

您在这里混合了一些东西。这应该是您的实体:

<?php 

namespace App\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Table(name="categories") 
* @ORM\Entity(repositoryClass="App\Entity\Repository\CategoriesRepository") 
*/ 
class Categories 
{ 
} 

在doc注释注释中它告诉Doctrine在哪里可以找到自定义存储库类。教义为你加载它。 存储不需要构造函数。学说为你照顾这件事。

<?php 

namespace App\Entity\Repository; 

use App\Entity\Categories; 
use Doctrine\ORM\EntityRepository; 

class CategoriesRepository extends EntityRepository implements CategoriesRepositoryInterface 
{ 
    // No constructor here 

    public function fetchAll() 
    { 
     // ... 
    } 
} 

然后你的工厂是这样的:

<?php 

namespace App\Panel\Factory; 

use Doctrine\ORM\EntityManager; 
use Interop\Container\ContainerInterface; 
use App\Entity\Categories; 

class CategoriesRepositoryFactory 
{ 
    /** 
    * @param ContainerInterface $container 
    * @return CategoriesRepository 
    */ 
    public function __invoke(ContainerInterface $container) 
    { 
     // Get the entitymanager and load the repository for the categories entity 
     return $container->get(EntityManager::class)->getRepository(Categories::class); 
    } 
} 

在您使用此配置:

<?php 

return [ 
    'dependencies' => [ 
     'invokables' => [ 
     ], 
     'abstract_factories' => [ 
     ], 
     'factories' => [ 
      App\Entity\Repository\CategoriesRepositoryInterface::class => App\Panel\Factory\CategoriesRepositoryFactory::class, 
     ], 
    ], 
]; 
+0

非常感谢你,海尔特Eltink,你怎么总是来的拯救! 甚至改变了配置中的字符串: 'App \ Panel \ Service \ CategoriesServiceInterface :: class => App \ Panel \ Factory \ CategoriesServiceFactory :: class,' – Drakulitka