2015-07-19 30 views
2

Zend Framework 2手冊的示例程序(日期爲2015年3月31日)不起作用。這是基本部分的代碼,它是一個文字副本。Zend Framework 2官方手冊的示例顯然不起作用

我想知道是否有人使用過它,如果有的話,它是否工作,以及如何。

application.config.php:

<?php 
/** 
* If you need an environment-specific system or application configuration, 
* there is an example in the documentation 
* @see http://framework.zend.com/manual/current/en/tutorials/config.advanced.html#environment-specific-system-configuration 
* @see http://framework.zend.com/manual/current/en/tutorials/config.advanced.html#environment-specific-application-configuration 
*/ 
return array(
    // This should be an array of module namespaces used in the application. 
    'modules' => array(
     'Application', 
     'Album', 
    ), 

    // These are various options for the listeners attached to the ModuleManager 
    'module_listener_options' => array(
     // This should be an array of paths in which modules reside. 
     // If a string key is provided, the listener will consider that a module 
     // namespace, the value of that key the specific path to that module's 
     // Module class. 
     'module_paths' => array(
      './module', 
      './vendor', 
     ), 

     // An array of paths from which to glob configuration files after 
     // modules are loaded. These effectively override configuration 
     // provided by modules themselves. Paths may use GLOB_BRACE notation. 
     'config_glob_paths' => array(
      'config/autoload/{{,*.}global,{,*.}local}.php', 
     ), 

     // Whether or not to enable a configuration cache. 
     // If enabled, the merged configuration will be cached and used in 
     // subsequent requests. 
     //'config_cache_enabled' => $booleanValue, 

     // The key used to create the configuration cache file name. 
     //'config_cache_key' => $stringKey, 

     // Whether or not to enable a module class map cache. 
     // If enabled, creates a module class map cache which will be used 
     // by in future requests, to reduce the autoloading process. 
     //'module_map_cache_enabled' => $booleanValue, 

     // The key used to create the class map cache file name. 
     //'module_map_cache_key' => $stringKey, 

     // The path in which to cache merged configuration. 
     //'cache_dir' => $stringPath, 

     // Whether or not to enable modules dependency checking. 
     // Enabled by default, prevents usage of modules that depend on other modules 
     // that weren't loaded. 
     // 'check_dependencies' => true, 
    ), 

    // Used to create an own service manager. May contain one or more child arrays. 
    //'service_listener_options' => array(
    //  array(
    //   'service_manager' => $stringServiceManagerName, 
    //   'config_key'  => $stringConfigKey, 
    //   'interface'  => $stringOptionalInterface, 
    //   'method'   => $stringRequiredMethodName, 
    // ), 
    //), 

    // Initial configuration with which to seed the ServiceManager. 
    // Should be compatible with Zend\ServiceManager\Config. 
    // 'service_manager' => array(), 
); 

Module.php:

<?php 

namespace Album; 

use Zend\ModuleManager\Feature\AutoloaderProviderInterface; 
use Zend\ModuleManager\Feature\ConfigProviderInterface; 

class Module implements AutoloaderProviderInterface, ConfigProviderInterface { 

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

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

} 

module.config.php:

<?php 

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


    '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() { 
     return new ViewModel(); 
    } 

    public function addAction() { 

    } 

    public function editAction() { 

    } 

    public function deleteAction() { 

    } 

} 

然後創建文件並將index.phtml放入正常文本。

加載到瀏覽器:

項目http://localhost/(name)/公/專輯

出現此錯誤:

Controller: not-found(resolves to invalid controller class or alias: not-found)

有誰知道會發生什麼?

+0

什麼是你的項目的名稱? – user2182349

+0

「項目名稱」是Zend骨架應用程序已安裝副本的名稱。它被安裝在XAMPP中,並且它在url中的索引方式就是這樣。下載時稱爲ZendSkeletonApplication-master.zip –

回答

0

Arg,我犯了一個笨拙的錯誤。參考控制器是錯誤的

module.config.php

'’controller' => 

真的是

'controller' =>