2016-05-31 52 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