我正在嘗試學習Zend Framework 2,並將其骨架應用程序啓動並運行。爲了訪問它,我訪問http://localhost:8080/。當訪問該鏈接時,它會顯示其通用Zend頁面。我想要能夠做的是訪問http://localhost:8080/application/test,並讓我帶着另一個不同版面的頁面。Zend Framework 2路由錯誤:解析爲無效的控制器類別或別名
這裏是module.config.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
),
// The following is a route to simplify getting started creating
// new controllers and actions without needing to create a new
// module. Simply drop new controllers in, and you can access them
// using the path /application/:controller/:action
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/application',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller[/:action]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
),
),
),
),
),
)
),
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
),
'translator' => array(
'locale' => 'en_US',
'translation_file_patterns' => array(
array(
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
),
),
),
'controllers' => array(
'invokables' => array(
'Application\Controller\Index' => 'Application\Controller\IndexController'
),
),
'view_manager' => array(
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => array(
'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
'error/404' => __DIR__ . '/../view/error/404.phtml',
'error/index' => __DIR__ . '/../view/error/index.phtml',
),
'template_path_stack' => array(
__DIR__ . '/../view',
),
),
// Placeholder for console routes
'console' => array(
'router' => array(
'routes' => array(
),
),
),
);
爲了讓這對我來說工作是我的嘗試:
首先,我創建了一個名爲中的TestController應用/ src目錄/應用控制器/控制器/。
接下來我添加了'application/test/index'=>DIR。 '/../view/application/test/index.phtml'到view_manager中的template_map數組中。
我還向控制器陣列添加了'Application \ Controller \ Test'=>'Application \ Controller \ TestController'。
當我訪問http://localhost:8080/application/test我得到的錯誤: 測試(解析爲無效的控制器類或別名:測試)
我明明做錯事,但TBH對Zend的文件是不是福利局友好的一切,它變得非常令人沮喪。有人能指出我正確的方向嗎?有這麼多的配置,我確信我錯過了一些小東西。謝謝!
我的上帝,你是一個聖人。非常感謝。 – cantread