ZF2路由配置 [英] ZF2 routing configuration
问题描述
我刚刚构建了一个zf2项目,但遇到配置问题.
I've just built a zf2 project and i'm having a configuration problem.
当我转到mydomain.com时,此行将按配置文件中的指定路由到应用程序模块,索引控制器,索引操作.
When i go to mydomain.com this routs as specified in configuration files to Application module, index controller, index action.
但是,如果我键入mydomain.com/otheraction,则不会路由到应用程序模块,索引控制器,otheraction操作.当然,由于未配置为执行此操作.
But If i type mydomain.com/otheraction this is not routed to Application module, index controller, otheraction action. Of course, since it isn't configured to do this.
所以我的问题是如何配置应用程序来做到这一点?我添加了我的Application/config/module.config.php文件和主配置文件.谢谢!
So my question would be how do i configure the app to do that? I've added my Application/config/module.config.php file and the main config file. Thank you!
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-2012 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(
'factories' => array(
'translator' => 'Zend\I18n\Translator\TranslatorServiceFactory',
),
),
'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',
),
),
);
application.config.php
<?php
return array(
'modules' => array(
'Application',
'ZfcBase',
'ZfcUser',
),
'module_listener_options' => array(
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php',
),
'module_paths' => array(
'./module',
'./vendor',
),
),
);
推荐答案
配置的默认路由是接受此格式的任何url,这是标准格式
The default route configured is to accept any url of this format, this is the standard format
mydomain.com/
mydomain.com/applicatiom/controller/action (standard format)
在您的情况下,mydomain.com/otheraction路由器希望模块执行其他动作,但该动作不存在.
in your case mydomain.com/otheraction the router expect a module otheraction, but its not present.
如果您需要上述指定的路线,请在该路线下输入一个条目
if you need to have a route as specified above have a entry under route
'otheraction' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/otheraction',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'otheraction',
),
),
),
这篇关于ZF2路由配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!