D
D
Dmitry Morozov2016-10-29 17:18:30
Zend Framework
Dmitry Morozov, 2016-10-29 17:18:30

When creating a new module in ZF 3, it says that there is no such class, how to solve this problem?

When creating a new module, let's say Blog, and all the settings (module.config.php | Module.php) and creating an IndexController, it writes an error that the Blog\Controller\IndexControllerFatal error class, although the IndexController file itself exists and is located in the Blog/src/Controller/ folder

<?php

namespace Blog\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        return new ViewModel();
    }
}

module.config.php settings
<?php

namespace Blog;

use Zend\Router\Http\Segment;
use Zend\ServiceManager\Factory\InvokableFactory;

return [
    'controllers' => [
        'factories' => [
            Controller\IndexController::class => InvokableFactory::class,
        ],
    ],
    'router' => [
        'routes' => [
            'blog' => [
                'type' => Segment::class,
                'options' => [
                    'route'    => '/blog',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ],
    'view_manager' => [
        'template_path_stack' => [
            __DIR__ . '/../view',
        ],
    ],
];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-10-29
@index1

It is necessary to register in the composer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question