【发布时间】:2016-01-28 14:36:49
【问题描述】:
我们有两个以上的 RESTful 模块(Restful 和 Testservices)。一次只有一个 REST 模块在工作。
-
如果我重新排列了 application.config.php 中的模块顺序,则 REST api 的最后一个模块正在工作。
例如,如果我在“Restful”模块之后保留“Testservices”模块,则“Testservices”正在工作。 示例 - Testservices:http://localhost/dev/public/testservices/Userslist 工作正常。
如果我打电话给这个http://localhost/dev/public/restful/stateslist 得到以下错误:
发生 404 错误 网页未找到。 请求的控制器无法分派请求。 控制器: 应用程序\控制器\索引
- 如果我在“Testservices”模块之后保留“Restful”模块,则“Restful”正在工作。得到与上述相反的错误。
这里是 application.config.php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'DoctrineModule',
'DoctrineORMModule',
'Application',
'Ads',
'Consumer',
'Restful',
'Cron',
'Admin',
'Payment',
'Frontoffice',
'Onboarding',
'Testservices',
),
// 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 overide 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(),
);
这里是 Restful 模块的 module.config.php
namespace Restful;
return array(
'controllers' => array(
'invokables' => array(
'Restful\Controller\Stateslist' => 'Restful\Controller\StateslistController',
'Restful\Controller\Citieslist' => 'Restful\Controller\CitieslistController',
),
),
'router' => array(
'routes' => array(
'api' => array(
'type' => 'Literal',
'options' => array(
'route' => '/Restful',
'defaults' => array(
'__NAMESPACE__' => 'Restful\Controller',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'api' => __DIR__ . '/../view',
),
'strategies' => array(
'ViewJsonStrategy'
)
),
);
这里是 Testservices 模块的 module.config.php
namespace Testservices;
return array(
'controllers' => array(
'invokables' => array(
'Testservices\Controller\Userslist' => 'Testservices\Controller\Userslist',
'Testservices\Controller\Roleslist' => 'Testservices\Controller\RoleslistController',
),
),
'router' => array(
'routes' => array(
'api' => array(
'type' => 'Literal',
'options' => array(
'route' => '/Testservices',
'defaults' => array(
'__NAMESPACE__' => 'Testservices\Controller',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '/[:controller]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*'
),
'defaults' => array(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'api' => __DIR__ . '/../view',
),
'strategies' => array(
'ViewJsonStrategy'
)
),
);
提前感谢您的帮助。
【问题讨论】:
标签: php rest zend-framework2