N
N
Nikolai Gromov2017-02-24 13:16:38
Zend Framework
Nikolai Gromov, 2017-02-24 13:16:38

Why doesn't ServiceManager start?

Hello.
I am getting this error

Unable to resolve service "CategoryManager" to a factory; are you certain you provided it during configuration?

and among other references to vendor files, also refers to
C:\xampp\htdocs\zblog.local\module\Admin\src\Controller\Factory\CategoryControllerFactory.php(19): Zend\ServiceManager\ServiceManager->get('Admin\\Service\\C...')

Here is the code for this file
<?php
namespace Admin\Controller\Factory;

use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
use Admin\Service\CategoryManager;
use Admin\Controller\CategoryController;

/**
 * Это фабрика для IndexController. Ее целью является инстанцирование
 * контроллера.
 */
class CategoryControllerFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, 
                     $requestedName, array $options = null)
    {
        $entityManager = $container->get('doctrine.entitymanager.orm_default');
        $categoryManager = $container->get(CategoryManager::class);

        // Инстанцируем контроллер и внедряем зависимости.
        return new CategoryController($entityManager, $categoryManager);
    }
}

and the code of the CategoryManager.php itself
<?php
namespace Admin\Service;

use Shop\Entity\Category;

// Сервис The CategoryManager, отвечающий за дополнение новых постов.
class CategoryManager 
{
    /**
     * Doctrine entity manager.
     * @var Doctrine\ORM\EntityManager
     */
    private $entityManager;
  
    // Конструктор, используемый для внедрения зависимостей в сервис.
    public function __construct($entityManager)
    {
        $this->entityManager = $entityManager;
    }
    
    // Этот метод добавляет новый пост.
    public function addNewCategory($data) 
    {
        // Создаем новую сущность Post.
        $category = new Category();
        $category->setParentId($data['parent_id']);
        $category->setCategory($data['category']);        
        
        // Добавляем сущность в менеджер сущностей.
        $this->entityManager->persist($category);
        
        // Применяем изменения к базе данных.
        $this->entityManager->flush();
    }
}

Tell me what's the problem.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question