从命令行运行index.php时出现RoutePluginManager异常

时间:2013-07-29 13:59:36

标签: zend-framework2

我试图在我的ZF2项目上集成Console模块,该项目目前还有2个其他工作模块。我创建了一个应用程序模块,并开始像http://framework.zend.com/manual/2.1/en/modules/zend.console.introduction.html

中描述的那样配置路由

但如果我从命令行运行php index.php(有或没有路由参数),我会得到这个漫长而奇怪的异常:

PHP Fatal error:  Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\Mvc\Router\RoutePluginManager::get was unable to fetch or create an instance for Segment' in /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:496
Stack trace:
#0 /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/AbstractPluginManager.php(103): Zend\ServiceManager\ServiceManager->get('Segment', true)
#1 /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/Router/SimpleRouteStack.php(274): Zend\ServiceManager\AbstractPluginManager->get('Segment', Array)
#2 /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php(78): Zend\Mvc\Router\SimpleRouteStack->routeFromArray(Array)
#3 /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/Router/Console/SimpleRouteStack.php(51): Zend\Mvc\Router\Console\SimpleRouteStack->routeFromArray(Array)
#4 /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/R in /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 496

Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\Mvc\Router\RoutePluginManager::get was unable to fetch or create an instance for Segment' in /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 496

Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\Mvc\Router\RoutePluginManager::get was unable to fetch or create an instance for Segment in /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 496

Call Stack:
    0.0011     636880   1. {main}() /www/APIO/public/index.php:0
    0.0048     933624   2. Zend\Mvc\Application::init() /www/APIO/public/index.php:21
    0.0752    6943968   3. Zend\Mvc\Application->bootstrap() /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:254
    0.0815    7543504   4. Zend\ServiceManager\ServiceManager->get() /www/APIO/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:153
    0.0815    7544296   5. Zend\ServiceManager\ServiceManager->create() /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:481
    0.0815    7544296   6. Zend\ServiceManager\ServiceManager->doCreate() /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:557
    0.0816    7544376   7. Zend\ServiceManager\ServiceManager->createFromFactory() /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:598
    0.0819    7565176   8. Zend\ServiceManager\ServiceManager->createServiceViaCallback() /www/APIO/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:983

我试图谷歌这个例外,但没有运气。有谁知道这个'Segment'服务无法创建?或者我的应用程序中可能存在错误配置的内容?

PS。在其他一些教程之后,我的Module.php看起来像这样:

class Module implements AutoloaderProviderInterface,
    ConfigProviderInterface,
    ConsoleUsageProviderInterface
{


    public function getConfig()
    {
        return include __DIR__ . '/config/module.config.php';
    }

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                ),
            ),
        );
    }

    /**
     * Returns a string containing a banner text, that describes the module and/or the application.
     * The banner is shown in the console window, when the user supplies invalid command-line parameters or invokes
     * the application with no parameters.
     *
     * The method is called with active Zend\Console\Adapter\AdapterInterface that can be used to directly access Console and send
     * output.
     *
     * @param Console $console
     * @return string|null
     */
    public function getConsoleBanner(Console $console)
    {
        // TODO: Implement getConsoleBanner() method.
        return 'Application 1.0';
    }

    public function getConsoleUsage(Console $console)
    {
        return array(
            'show stats'             => 'Show application statistics',
            'run cron'               => 'Run automated jobs',
            '(enable|disable) debug' => 'Enable or disable debug mode for the application.'
        );
    }
}

修改

这里还有module.config.php文件

<?php

return array(
    'router' => array(
        'routes' => array(
        ),
        'console' => array(
            'calculate-distances' => array(
                'options' => array(
                    'route'    => 'user calculatedistances [--id=]',
                    'defaults' => array(
                        'controller' => 'Application\Controller\Index',
                        'action'     => 'calculate-distances'
                    )
                )
            )
        )
    ),

    'controllers' => array(
        'invokables' => array(
            'Application\Controller\Index' => 'Application\Controller\IndexController'
        ),
    ),
    'service_manager' => array(
        'abstract_factories' => array(
            'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
            'Zend\Log\LoggerAbstractServiceFactory',
        ),
    ),
);

0 个答案:

没有答案