从控制器CakePHP 3.x执行外壳 [英] Execute shell from controller CakePHP 3.x
问题描述
我在CakePHP Shell中有一个特定的任务,它由CRON作业执行。但是我希望用户能够在需要时从Web界面(例如按钮或类似的东西)执行它。
I have a specific task in a CakePHP Shell and it's executed by a CRON job. But I want the users to be able to execute it from a web interface (like a button or something like this) whenever he wants.
所以,我的问题是可以从控制器执行shell吗?
So, my question is, is this possible to execute a shell from a controller ?
在控制器中模拟它:
bin/cake MyShell
我知道在早期版本的CakePHP中,但我没有在最新版本中找到与此相关的内容。并使用 exec( bin / cake MyShell)对我来说真的很脏。
I know it was possible in the previous versions of CakePHP, but I didn't find something related to this in the newest version. And use exec("bin/cake MyShell") seems really dirty to me.
推荐答案
create一个shell对象,调用其要执行的任何函数
create a shell object , the call any of its function to want to excute
$myShell = new \App\Shell\MyShell;
$myShell->anyShellFun();
这篇关于从控制器CakePHP 3.x执行外壳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!