0

请帮忙理解。
在标准应用程序 CRUD 中,在连接服务时:
/src/App/Panel/Service/CategoriesService.php
在行动中:
/src/App/Panel/Action/PanelCategoriesAction.php发生 500 错误
链接到存储库:https ://github.com/drakulitka/expressive.loc.git
Zend Expressive + Doctrine

对不起我的英语不好

4

1 回答 1

1

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

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

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

在文档注释注释中,它告诉 Doctrine 在哪里可以找到自定义存储库类。教义为您加载它。存储库不需要构造函数。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,
        ],
    ],
];
于 2016-05-31T17:15:35.997 回答