你如何在 CakePHP 2 中 运行 全局插件的 shell?
How do you run a global plugin's shell in CakePHP 2?
- 我在 CakePHP 2.6.3 的
PluginName/Console/Command/FooShell.php
中有一个 shell。
- 我已经通过
CakePlugin::load('PluginName');
在我的应用程序 bootstrap.php
中加载了这个插件。
- 当那个插件在
ROOT/app_name/Plugin
时,我 运行 PluginName.foo
, shell 工作 .
- 当那个插件在
ROOT/plugins
和我 运行 相同的命令时,我得到一个错误:
命令:
C:\xampp\htdocs\site_name\app_name>php Console/cake.php -app app_name PluginName.foo
错误:
Warning Error: include(C:\xampp\htdocs\site_name\app_name\Plugin\PluginName\Console\Command\FooShell.php): failed to open stream: No such file or directory in [C:\xampp\htdocs\site_name\lib\Cake\Core\App.php, line 547]
Warning Error: include(): Failed opening 'C:\xampp\htdocs\site_name\app_name\Plugin\PluginName\Console\Command\FooShell.php' for inclusion (include_path='C:\xampp\htdocs\site_name\lib;.;C:\xampp\php\PEAR') in [C:\xampp\htdocs\site_name\lib\Cake\Core\App.php, line 547]
Error: Shell class FooShell could not be found.
#0 C:\xampp\htdocs\site_name\lib\Cake\Console\ShellDispatcher.php(200): ShellDispatcher->_getShell('PluginName.back...')
#1 C:\xampp\htdocs\site_name\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()
#2 C:\xampp\htdocs\site_name\app_name\Console\cake.php(33): ShellDispatcher::run(Array)
#3 {main}
出于某种原因,CakePHP 可以在 ROOT/plugins
中为实际网页提供此插件,但会在控制台中抛出错误。
shell docs or the plugin docs explicitly says that there's anything different about using plugins in ROOT/plugins
, but discussion of how that directory is used is conspicuously absent from the plugin and folder structure docs 中没有内容。 (我假设是因为它暗示你应该以相同的方式实现插件,不管它们在哪个目录中。)
我做错了吗?
当它在 ROOT/plugins
目录中时,您需要像这样在 ROOT/lib/Cake/bootstrap.php
中加载它
App::build(array('Plugin' => array(CAKE . DS . 'plugins' . DS)));
CakePlugin::load('<plugin-name>');
- 我在 CakePHP 2.6.3 的
PluginName/Console/Command/FooShell.php
中有一个 shell。 - 我已经通过
CakePlugin::load('PluginName');
在我的应用程序bootstrap.php
中加载了这个插件。 - 当那个插件在
ROOT/app_name/Plugin
时,我 运行PluginName.foo
, shell 工作 . - 当那个插件在
ROOT/plugins
和我 运行 相同的命令时,我得到一个错误:
命令:
C:\xampp\htdocs\site_name\app_name>php Console/cake.php -app app_name PluginName.foo
错误:
Warning Error: include(C:\xampp\htdocs\site_name\app_name\Plugin\PluginName\Console\Command\FooShell.php): failed to open stream: No such file or directory in [C:\xampp\htdocs\site_name\lib\Cake\Core\App.php, line 547]
Warning Error: include(): Failed opening 'C:\xampp\htdocs\site_name\app_name\Plugin\PluginName\Console\Command\FooShell.php' for inclusion (include_path='C:\xampp\htdocs\site_name\lib;.;C:\xampp\php\PEAR') in [C:\xampp\htdocs\site_name\lib\Cake\Core\App.php, line 547]
Error: Shell class FooShell could not be found.
#0 C:\xampp\htdocs\site_name\lib\Cake\Console\ShellDispatcher.php(200): ShellDispatcher->_getShell('PluginName.back...')
#1 C:\xampp\htdocs\site_name\lib\Cake\Console\ShellDispatcher.php(66): ShellDispatcher->dispatch()
#2 C:\xampp\htdocs\site_name\app_name\Console\cake.php(33): ShellDispatcher::run(Array)
#3 {main}
出于某种原因,CakePHP 可以在 ROOT/plugins
中为实际网页提供此插件,但会在控制台中抛出错误。
shell docs or the plugin docs explicitly says that there's anything different about using plugins in ROOT/plugins
, but discussion of how that directory is used is conspicuously absent from the plugin and folder structure docs 中没有内容。 (我假设是因为它暗示你应该以相同的方式实现插件,不管它们在哪个目录中。)
我做错了吗?
当它在 ROOT/plugins
目录中时,您需要像这样在 ROOT/lib/Cake/bootstrap.php
App::build(array('Plugin' => array(CAKE . DS . 'plugins' . DS)));
CakePlugin::load('<plugin-name>');