How can I fix the Class 'Album \ Controller \ AlbumController' error?

I'm new to Zend Framework 2. I have created a folder structure and paste the code snippets from this page http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html about routing in Zend Framework 2.

I am getting the following error:

( ! ) Fatal error: Class 'Album\Controller\AlbumController' not found in C:\wamp\www\zend\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php on line 178

      

Below is my classmap_autoload.php

<?php 
return array();

      

Below is the Module.php module   

namespace Album;

class Module {
    public function getAutoloaderConfig(){
        return array(
            'Zend\Loader\ClassMapAutoloader' => array(
                __DIR__.'/autoload_classmap.php',
            ),
            'Zend\Loader\StandardAutoloader' => array(
                'namespace' => array(
                    __NAMESPACE__ => __DIR__.'/src/'.__NAMESPACE__,
                ),
            ),
        );
    }

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

}

      

I have a class AlbumController

already inmodule/Album/

enter image description here

Here's mine module.config.php

from the Album module:

<?php 

return array(
    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',
        ),
    ),

     // The following section is new and should be added to your file
    'router' => array(
        'routes' => array(
            'album' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/album[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Album\Controller\Album',
                        'action'     => 'index',
                    ),
                ),
            ),
        ),
    ),

    'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),
);

      

AlbumCOntroller.php

<?php


namespace Album\Controller;

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

class AlbumController extends AbstractActionController
{
    public function indexAction()
    {
    }

    public function addAction()
    {
    }

    public function editAction()
    {
    }

    public function deleteAction()
    {
    }
}

      

I have no idea why I have this error. I would like to know what is going on inside Zend before making the page, but before I intend to resolve this issue. How can I fix this?

+3


source to share


2 answers


Module.php 'namespace' => array

must have namespaces

(plural)



Also you can compare your code with https://github.com/zendframework/zf2-tutorial

+11


source


I am currently playing with tutorial and integrated teaching. The above issue can appear with "namespaces", perhaps after calling composer to update, as the name of ActionController apparently magically changed to AbstractActionController

.

Without warning.



edit After checking, I realized that the doctrine code was outdated, so by inserting the replacement the controller name became obsolete.

0


source







All Articles