2012-07-05 126 views
2

我試圖關注Akrabats Tutorial應用程序/索引正在工作,而不是相冊部分。Zend Framework 2 MVC - 模塊路由映射不起作用

我試過它也與ZendSkeletonModule沒有運氣。

錯誤在這兩種情況是:

album/album (resolves to invalid controller class or alias: album/album)

我ZF2主人和BETA4標籤嘗試過(但BETA4標籤使PHP的錯誤有關缺少方法getEventManager)

我把代碼Akrabats教程,並在此之後使用代碼形式GitHub Repo。不幸的是,沒有一些論壇或評論部分尋求幫助。

我發現教程中的一些差異和module.config.php(我相信是問題的核心)的骨架(zfcUser具有相同的差異)。

本教程在控制器索引中使用classes,zfcUser和使用invokables的Skeleton,但它似乎並不重要,因爲錯誤不會改變。

我module.config目前看起來是這樣的:

<?php 

return array(

    // Controllers in this module 
    'controller' => array(
     'invokables' => array(
      'album/album' => 'Album\Controller\AlbumController', 
     ),   
    ), 


    // Routes for this module 
    'router' => array(
     'routes' => array(
      'album' => array(
       'type' => 'Literal', 
       'priority' => 1000, 
       'options' => array(
        'route' => '/album', 
        'defaults' => array(
         'controller' => 'album/album', 
         'action' => 'index', 
        ), 
       ), 
       'may_terminate' => true, 
       'child_routes' => array( 
        'misc' => 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/album', 
           'action'  => 'index', 
          ), 
         ), 
        ), 
       ), 
      ), 
     ), 
    ),  

    // View setup for this module 
    'view_manager' => array(
     'template_path_stack' => array(
      'album' => __DIR__ . '/../view', 
     ), 
    ), 
); 

專輯\控制器\ AlbumController:

<?php 

namespace Album\Controller; 

use Zend\Mvc\Controller\ActionController, 
    Zend\View\Model\ViewModel, 
    Album\Model\AlbumTable, 
    Album\Model\Album, 
    Album\Form\AlbumForm; 

class AlbumController extends ActionController 
{ 
// [....] 
} 

我不知道去哪裏找解決這個錯誤,做你一個人有一個理念?

代碼與github上的原始代碼相同(請參閱上面的鏈接),除非另有說明。

TIA

回答

7

的區別就在這裏不僅是invokables,而且該數組關鍵是現在「控制器s」複數,這是我的伎倆。在你的代碼中,「invokables」已經改變了,但你似乎使用「controller」作爲鍵。

'controllers' => array(
      'invokables' => array(
        'album/album' => 'Album\Controller\AlbumController', 
      ), 
    ), 
+0

歡迎來到SO,感謝您的發現。 – Rufinus 2012-07-08 08:35:37

3

發現了它,它的ActionController類似乎在ZF2-BETA4想要離去讓你AlbumController 需要是這樣的:

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

class AlbumController extends AbstractActionController { 
    ..... 
} 
+0

您好,歡迎SO。你是對的,(足夠intresting它不會引發ActionController的錯誤),但路由問題不是由它修復。 – Rufinus 2012-07-06 05:24:09

+0

同樣的問題,更改爲AbstractActionController,並且仍然存在路由問題。 – 2012-07-06 10:27:15

+0

正如Armand說的那樣,您需要將module.config.php更改爲可調用 – AlexWS 2012-07-06 15:47:38

4

顯然有數組中的變化控制器。現在關鍵的類別改爲invokables: 在module.config.php

'controller' => array(
      'classes' => array(
        'album/album' => 'Album\Controller\AlbumController', 
      ), 
    ), 

必須改變以

'controllers' => array(
      'invokables' => array(
        'album/album' => 'Album\Controller\AlbumController', 
      ), 
    ), 
+0

,如您在代碼中所見,此更改已完成。 – Rufinus 2012-07-06 10:57:28

+0

你好Rufinus,我沒有注意到你的代碼。無論如何,這個變化解決了我的問題。 – 2012-07-06 11:09:22

+0

+阿爾芒我錯過了你的改變,以「控制器」作爲+ sirkohli提到。我給了他正確答案的標誌,他是一個新成員。還是要謝謝你的幫助。 – Rufinus 2012-07-08 08:36:33

0

您必須正確配置/ application.config.php

<?php 
return array(
    'modules' => array(
     'Application', 
     'Album', 
    ), 
    'module_listener_options' => array(
     'config_glob_paths' => array(
      'config/autoload/{,*.}{global,local}.php', 
     ), 
     'module_paths' => array(
      './module', 
      './vendor', 
     ), 
    ), 
);