如何修复Class'Album\Controller\AlbumController'未找到错误?

Vim*_*deo 3 php zend-framework2

我在Zend框架2.新手我创建的文件夹结构,并从该网页粘贴代码片段http://framework.zend.com/manual/2.0/en/user-guide/routing-and-controllers.html约Zend Framework 2中的路由.

我收到以下错误:

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

下面是我的classmap_autoload.php

<?php 
return array();
Run Code Online (Sandbox Code Playgroud)

下面是Module.php

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';
    }

}
Run Code Online (Sandbox Code Playgroud)

我的AlbumController班级已经上课了module/Album/ 在此输入图像描述

这是我module.config.php的相册模块:

<?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',
        ),
    ),
);
Run Code Online (Sandbox Code Playgroud)

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()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会出现这样的错误..我想在渲染页面之前了解Zend内部发生了什么,但在我打算解决这个问题之前..我该如何解决这个问题?

Mak*_*s3w 11

在Module.php中'namespace' => array必须是namespaces(复数形式)

您还可以将您的代码与https://github.com/zendframework/zf2-tutorial进行比较