我正在尝试在Cli命名空间下为我的 zf2 应用程序创建一个控制台感知模块。我刚刚用一个简单的控制器、模块配置文件和 Module.php 创建了模块目录。
问题是当我在命令行上调用“php public/index.php”时,在我的应用程序控制台横幅之后,我得到了 DoctrineModule 的默认 Cli 输出,如下所示:
➜ myapp git:(master) ✗ php public/index.php
--- This is app banner ---
----------------------------------------------
DoctrineModule
----------------------------------------------
DoctrineModule Command Line Interface version 0.8.0
Usage:
[options] command [arguments]
... bla bla ...
模块/Cli/config/module.config.php:
return array(
'console' => array(
'router' => array(
'routes' => array(
'testroute' => array(
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Cli\Controller\Index',
'action' => 'index'
)
)
)
)
)
),
);
module/Cli/Module.php 的内容:
<?php
namespace Cli;
use Zend\ModuleManager\Feature\ConsoleBannerProviderInterface;
use Zend\Console\Adapter\AdapterInterface as Console;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements AutoloaderProviderInterface, ConsoleBannerProviderInterface
{
public function getConsoleBanner(Console $console){
return "--- This is app banner ---\n";
}
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src'
)
)
);
}
}