Run plugin's shell in cakephp 2.0

喜欢而已 提交于 2019-12-22 07:13:05

问题


I have created a new CakePHP 2.0 app and want to run a plugin's shell.

<?php
// app\Plugin\Tmaker\Vendors\Shells\TmakerShell.php
class TmakerShell extends Shell {  
}

However, I can't see it when running Console/cake from the command-line.

Please advise my what I have missed?


回答1:


According to the latest documentation, the path for shells has changed to app/Console/Command/.

Move your shell to the following location: app/Plugin/Tmaker/Console/Command/TmakerShell.php (not sure if plugin directory names are camel-cased in CakePHP 2.0, but it seems to work either way.)

<?php
class TmakerShell extends Shell {
    public function main() {
        $this->out('It works!');
    }
}

As CakePHP 2.0 requires you to load plugins manually, you also need to update app/Config/bootstrap.php by adding CakePlugin::loadAll(); or CakePlugin::load('Tmaker'); to the last line.

You should then be able to access your shell from the command-line. It looks like this in Windows:

C:\xampplite\htdocs\cake2\app>..\lib\Cake\Console\cake Tmaker.tmaker

Welcome to CakePHP v2.0.0-beta Console
---------------------------------------------------------------
App : app
Path: C:\xampplite\htdocs\cake2\app\
---------------------------------------------------------------
It works!


来源:https://stackoverflow.com/questions/6979442/run-plugins-shell-in-cakephp-2-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!