Answer the question
In order to leave comments, you need to log in
Why doesn't the controller work in ZF3?
Hello. Faced with the following situation. Created a standard skeleton of the third zend through the composer. There is a ready-made index controller out of the box. When I work with it, everything is in perfect order, but when I try to create my own controller, problems arise. The error as such does not crash and even the template is displayed, but the logic of the controller itself is dead for some reason. I even tried to prescribe die in the controller and even it does not work. Although everything works in the index controller.
With regards to the actions that I took to register a new controller and a route to it.
In configs:
'blog' => [
'type' => Literal::class,
'options' => [
'route' => '/test',
'defaults' => [
'controller' => Controller\BlogController::class,
'action' => 'index',
],
],
],
'controllers' => [
'factories' => [
Controller\IndexController::class => InvokableFactory::class,
Controller\BlogController::class => InvokableFactory::class,
],
],
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class BlogController extends AbstractActionController
{
public function index()
{
return ViewModel([
'var' => 'variable value'
]);
}
}
Answer the question
In order to leave comments, you need to log in
Action methods in the controller must end with Action
In your case:
public function indexAction()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question