0

Please help to understand.
In the standard application CRUD, at connection of Service:
/src/App/Panel/Service/CategoriesService.php
in Action:
/src/App/Panel/Action/PanelCategoriesAction.php happens 500 error
link to repository: https://github.com/drakulitka/expressive.loc.git
Zend Expressive + Doctrine

Sorry for my English

Drakulitka
  • 41
  • 6

1 Answers1

1

You are mixing a few things up here. This should be your entity:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

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

In the doc comment annotation it tells Doctrine where to find the custom repository class. Doctrine loads it for you. The repositry doesn't need a constructor. Doctrine takes care of this for you.

<?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()
    {
        // ...
    }
}

And then your factory looks like this:

<?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);
    }
}

In the config you use this:

<?php

return [
    'dependencies' => [
        'invokables' => [
        ],
        'abstract_factories' => [
        ],
        'factories' => [
            App\Entity\Repository\CategoriesRepositoryInterface::class => App\Panel\Factory\CategoriesRepositoryFactory::class,
        ],
    ],
];
xtreamwayz
  • 1,285
  • 8
  • 10
  • Thank you very much, Geert Eltink, how are You always come to the rescue! Even changed the string in configuration: `App\Panel\Service\CategoriesServiceInterface::class => App\Panel\Factory\CategoriesServiceFactory::class,` – Drakulitka Jun 01 '16 at 06:21