1
votes

I am using ZfcAdmin module for ZF2 (https://github.com/ZF-Commons/ZfcAdmin/) and I can't go through using my own controller.

According to the module documentation (https://github.com/ZF-Commons/ZfcAdmin/blob/master/docs/2.Routes.md) I should be able to use my own controller after simply adding this snippet from docs in my new module routes config, however it just cause a redirect to main page as it didn't find the route. So I've added this part:

'controllers' => array(
    'invokables' => array(
      'Admin\Controller\Admin' => 'Admin\Controller\AdminController',
    ),
),

Which results in error:

Exception: Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "admincontrolleradmin(alias: Admin/Controller/Admin)" via invokable class "Admin\Controller\AdminController"; class does not exist in /var/www/app/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:240

Module.php

<?php
namespace Admin;

class Module
{
  public function getConfig()
  {
    return include __DIR__ . '/config/module.config.php';
  }

  public function getAutoloaderConfig()
  {
    return array(
      'Zend\Loader\StandardAutoloader' => array(
        'namespaces' => array(
          __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
        ),
      )
    );
  }
}

module.config.php

<?php
return array(
  'controllers' => array(
    'invokables' => array(
      'Admin\Controller\Admin' => 'Admin\Controller\AdminController',
    ),
  ),


  'router' => array(
    'routes' => array(
      'zfcadmin' => array(
        'options' => array(
          'defaults' => array(
            'controller' => 'Admin/Controller/Admin',
            'action'     => 'test',
          ),
        ),
      ),
    ),
  ),
);

module/Admin/src/Admin/AdminController.php

<?php

namespace Admin\Controller;

use Zend\Mvc\Controller\AbstractActionController;

class AdminController extends AbstractActionController
{
  public function testAction()
  {
    echo('test');
    die();
  }
}

I am 99% sure it's my fault, not zfcadmin itself. Even though, I have no idea where I made a mistake while creating my own controller which can't be found.

1

1 Answers

1
votes

Zend 2 cannot find your "AdminController.php".

Your best option is to change "AdminController.php" to be under "module/Admin/src/Controller/", not "module/Admin/src/Admin/".