Php Zend framework 2中的Zend\ServiceManager\Exception\ServiceNotFoundException
我已经在我的系统上安装了Zf2框架Php Zend framework 2中的Zend\ServiceManager\Exception\ServiceNotFoundException,php,zend-framework2,Php,Zend Framework2,我已经在我的系统上安装了Zf2框架 它的工作Localhost骨架zend应用程序示例页面 当我在项目中插入新模块时,出现错误: Zend\ServiceManager\Exception\ServiceNotFoundException Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "userscontrollerindex(alias: Users\Controller\In
它的工作Localhost骨架zend应用程序示例页面
当我在项目中插入新模块时,出现错误:
Zend\ServiceManager\Exception\ServiceNotFoundException
Zend\Mvc\Controller\ControllerManager::createFromInvokable: failed retrieving "userscontrollerindex(alias: Users\Controller\Index)" via invokable class "Users\Controller\IndexController"; class does not exist
#0 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(637): Zend\ServiceManager\AbstractPluginManager->createFromInvokable('userscontroller...', 'Users\\Controlle...')
#1 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(593): Zend\ServiceManager\ServiceManager->doCreate('Users\\Controlle...', 'userscontroller...')
#2 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(525): Zend\ServiceManager\ServiceManager->create(Array)
#3 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\ServiceManager\AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('Users\\Controlle...', false)
#4 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\ControllerManager.php(137): Zend\ServiceManager\AbstractPluginManager->get('Users\\Controlle...', Array, false)
#5 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(96): Zend\Mvc\Controller\ControllerManager->get('Users\\Controlle...')
#6 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#7 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#8 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#9 D:\xampp\htdocs\CommunicationApp\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 D:\xampp\htdocs\CommunicationApp\public\index.php(17): Zend\Mvc\Application->run()
#11 {main}
在此附上我的代码:
module.config.php
<?php
return array(
'controllers' => array(
'invokables' => array(
'Users\Controller\Index' =>
'Users\Controller\IndexController',
),
),
'router' => array(
'routes' => array(
'users' => array(
'type' => 'Literal',
'options' => array(
// Change this to something specific to your module
'route' => '/users',
'defaults' => array(
// Change this value to reflect the namespace in which
// the controllers for your module are found
'__NAMESPACE__' => 'Users\Controller',
'controller' => 'Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
// This route is a sane default when developing a module;
// as you solidify the routes for your module, however,
// you may want to remove it and replace it with more
// specific routes.
'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(
),
),
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'users' => __DIR__ . '/../view',
),
),
);
<?php
return array(
// This should be an array of module namespaces used in the application.
'modules' => array(
'Application',
'Users',
),
// 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 override 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(),
);
问题可能在自动加载的_classmap.php文件中。 尝试编辑文件以
<?php
return array('Users\Controller\IndexController' => __DIR__ . '/Controller/IndexController.php',);
从您上面的评论来看,您的Users IndexController中似乎有错误的名称空间。你能把那个文件寄出去吗?命名空间应该是用户\控制器而不是应用程序\控制器。请删除`命名空间=>目录'/src/'。str_replace(“\”、“/”、名称空间)
`关于Module.php
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/ZendSkeletonModule 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
*/
namespace Users;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;
class Module implements AutoloaderProviderInterface
{
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
// if we're in a namespace deeper than one level we need to fix the \ in the path
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
public function onBootstrap(MvcEvent $e)
{
// You may not need to do this if you're doing it elsewhere in your
// application
$eventManager = $e->getApplication()->getEventManager();
$moduleRouteListener = new ModuleRouteListener();
$moduleRouteListener->attach($eventManager);
}
}
并替换为\uuuuuuu名称空间\uuuuu=>\ uuuuuuuu目录/src/'__NAMESPACE_uuu,),
请检查您是否更改了UserController.php中的类名您可能错过了更改类名“class UserController extensed AbstractActionController”的机会谢谢u@kamlesh.bar我将检查感谢u的评论u提及controller.php文件?没有文件是create usercontroller.phpFile名称应该是usercontroller.php,在该文件中检查“class usercontroller extensed AbstractActionController”,我创建了indexcontroller.php代码:namespace Application\Controller;使用Zend\Mvc\Controller\AbstractActionController;使用Zend\View\Model\ViewModel;类IndexController扩展AbstractActionController{public function indexAction(){return new ViewModel();}}
<?php
return array('Users\Controller\IndexController' => __DIR__ . '/Controller/IndexController.php',);