Execute shell from controller CakePHP 3.x(从控制器 CakePHP 3.x 执行 shell)
问题描述
我在 CakePHP Shell 中有一项特定任务,它由 CRON 作业执行.但我希望用户能够随时从网络界面(如按钮或类似的东西)执行它.
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.
推荐答案
创建一个shell对象,调用它的任何一个要执行的函数
create a shell object , the call any of its function to want to excute
$myShell = new AppShellMyShell;
$myShell->anyShellFun();
这篇关于从控制器 CakePHP 3.x 执行 shell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从控制器 CakePHP 3.x 执行 shell


基础教程推荐
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- php中的foreach复选框POST 2021-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- php中的PDF导出 2022-01-01
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- 将变量从树枝传递给 js 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01