我有以下ZF2配置:
<?php
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
),
'application' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:controller[/:action]][/:id][/:pId][/:devId]', //edited by Dibyendu
'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',
),
'factories' => array(
'translator' => 'Zend\Mvc\Service\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',
'Application\Controller\Upload' => 'Application\Controller\UploadController'
),
),
'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(
),
),
),
);
现在我有控制器Upload
,它有三个动作:
indexAction
uploadtestAction
uploadmusicAction
一般来说,这些网页的网址如下:
答案 0 :(得分:0)
我的工作空间没有打开,所以这是在黑暗中拍摄的。 抱歉
您是否尝试过使用类似于RESTful服务的架构? This file是我经常使用的服务控制器,它给了我类似于你的路由。
indexAction
使用该参数,并将方法链传递给您选择的内部函数。 请不要通过REST标准判断我的服务。它让我觉得那里的服务很脏:) 有来更新它一天。
在您的用例中:
您的路线看起来像
'upload' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/Upload',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Upload',
),
),
'may_terminate' => true,
'child_routes' => array(
'client' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:type][/:id]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'controller' => 'Upload',
'action' => 'index'
),
),
),
),
),
并且您的indexController
将在其切换中使用$type
来指导流程。