In Zend Framework 2 it's very simple to add the initial module banner to the console applications.
在Zend Framework 2中,将初始模块标题添加到控制台应用程序非常简单。
All we need to is to implement the getConsoleBanner
and getConsoleUsage
methods and implement the Zend\ModuleManager\Feature\ConsoleUsageProviderInterface
or ConsoleBannerProviderInterface
interfaces.
我们所需要的只是实现getConsoleBanner和getConsoleUsage方法,并实现Zend \ ModuleManager \ Feature \ ConsoleUsageProviderInterface或ConsoleBannerProviderInterface接口。
This is good enough to dump those messages in the console when public/index.php
is started via CLI.
当通过CLI启动public / index.php时,这足以将这些消息转储到控制台中。
In Zend Framework 3 it's not the same.
在Zend Framework 3中,它不一样。
Doing the same setup does not provide the same result. Actually in the console we see the default html page for the skeleton app the same way as we visit it via the browser.
执行相同的设置不会提供相同的结果。实际上在控制台中我们看到骨架应用程序的默认html页面与我们通过浏览器访问它的方式相同。
That page is being seen before we install the custom module: Here are the docs for the zend-mvc-console
module https://zendframework.github.io/zend-mvc-console/intro/
在我们安装自定义模块之前会看到该页面:以下是zend-mvc-console模块的文档https://zendframework.github.io/zend-mvc-console/intro/
Even after module is installed as suggested ('Zend\Mvc\Console'
added in module definitions) the console banners are not shown. I've tested with var dumping inside the methods and I'm able to view the data, so the framework executes those methods but shows no result in the console.
即使按照建议安装模块(模块定义中添加了“Zend \ Mvc \ Console”),也不会显示控制台横幅。我已经在方法中测试了var dumping并且我能够查看数据,因此框架执行这些方法但在控制台中没有显示结果。
I've tested with console routes and controllers. Route is found, controller action is executed but nothing is shown in the cli again.
我已经测试过控制台路由和控制器。找到路径,执行控制器操作但是cli中没有显示任何内容。
I've digged in the code of the framework and it seems the Zend\Mvc\Console\ResponseSender\ConsoleResponseSender
class is never executed.
我已经挖掘了框架的代码,似乎从未执行过Zend \ _ Mvc \ Console \ ResponseSender \ ConsoleResponseSender类。
Do I have to register some view_manager
strategies in order to get something displayed in the CLI?
我是否必须注册一些view_manager策略才能在CLI中显示某些内容?
Here are the sources on top of the zf3 skeleton application: https://gist.github.com/kachar/06f0c9096bcc1cc0b00f4612aed1b68b
以下是zf3骨架应用程序的源代码:https://gist.github.com/kachar/06f0c9096bcc1cc0b00f4612aed1b68b
Running the app:
运行应用程序:
$ php -v
PHP 7.0.6 (cli) (built: Apr 27 2016 14:00:40) ( ZTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
$ php public/index.php
Application\Module::getConsoleBanner
Application\Module::getConsoleUsage
$ php public/index.php user
Application\Controller\IndexController::indexAction
2 个解决方案
#1
8
Per our own documentation, MVC <-> Console integration is deprecated. We recommend using zf-console or symfony console for building console functionality for your application.
根据我们自己的文档,不推荐使用MVC < - >控制台集成。我们建议使用zf-console或symfony console为您的应用程序构建控制台功能。
We are aware of issues with zend-mvc-console, and we'll be issuing a patch release soon to address them, which will fix your short-term problems. However, we recommend migrating to another solution in the long-term.
我们知道zend-mvc-console存在的问题,我们很快就会发布一个补丁版本来解决它们,这将解决你的短期问题。但是,我们建议长期迁移到另一个解决方案。
#2
2
You can use the zend-mvc-console module. Same API as zf2 console :) Please not that this module will be deprecated soon.
您可以使用zend-mvc-console模块。与zf2控制台相同的API :)请注意,该模块很快就会被弃用。
Sources:
#1
8
Per our own documentation, MVC <-> Console integration is deprecated. We recommend using zf-console or symfony console for building console functionality for your application.
根据我们自己的文档,不推荐使用MVC < - >控制台集成。我们建议使用zf-console或symfony console为您的应用程序构建控制台功能。
We are aware of issues with zend-mvc-console, and we'll be issuing a patch release soon to address them, which will fix your short-term problems. However, we recommend migrating to another solution in the long-term.
我们知道zend-mvc-console存在的问题,我们很快就会发布一个补丁版本来解决它们,这将解决你的短期问题。但是,我们建议长期迁移到另一个解决方案。
#2
2
You can use the zend-mvc-console module. Same API as zf2 console :) Please not that this module will be deprecated soon.
您可以使用zend-mvc-console模块。与zf2控制台相同的API :)请注意,该模块很快就会被弃用。
Sources: