G
G
glebvvs2018-12-17 03:31:51
Zend Framework
glebvvs, 2018-12-17 03:31:51

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,
        ],
    ],

The controller itself:
<?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'
    ]);
  }

}

What's interesting is that even if the controller method has an empty body, the route template is rendered. But if you enter any logic into the controller, then for some reason it passes by. Someone faced such a problem? Maybe I missed a pitfall from the documentation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krutikov, 2019-02-12
@Sunsetboy

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 question

Ask a Question

731 491 924 answers to any question