php - 如何在 Controller cakephp 2 中声明/导出 ShellDispatcher?
问题描述
我正在关注这篇文章https://medium.com/@narendravaghela/cakephp-execute-shell-command-from-controller-90c8323558a并被找不到的 ShellDispatcher 卡住。
<?php
//namespace App\Controller;
//use App\Controller\AppController;
//use Cake\Console\ShellDispatcher;
class ExampleController extends AppController
{
public function index()
{
$shell = new ShellDispatcher();
$output = $shell->run(['cake', 'foo']);
if (0 === $output) {
$this->Flash->success('Success from shell command.');
} else {
$this->Flash->error('Failure from shell command.');
}
return $this->redirect('/');
}
}
了解您关于已提交前三行的问题:) 但在这种情况下,也可以找到它们中的每一个。我的 ShellDispatcher.php 在其中,lib\Cake\Console\ShellDispatcher
但这use lib\Cake\Console\ShellDispatcher;
也给了我一个错误“未找到”。我做错了什么?
我尝试像App::uses('ShellDispatcher', 'Console');
在我的代码中那样做,但是得到了这个错误Fatal error: Cannot declare class App, because the name is already in use in /var/www/html/lib/Cake/Core/App.php on line 65
解决方案
推荐阅读
- ruby-on-rails - 如何采摘然后连接数组中的最后两个
- java - 扫描仪问题和文本中的字母“Ł” - JAVA
- while-loop - 如何修复 llvm 寄存器增量错误?
- google-search - 在虚拟主机中禁用 robots.txt 中的子域索引
- sql - 在sql中检索最新结果
- mongodb - 蒙哥。如何通过 _id 的时间戳更新 createdAt
- authentication - 如果我们有多个重定向 uri,那么在 Azure AD 登录后将选择哪一个
- c - 从函数返回时无法接收节点指针的值
- python - 分别记录 Flask 请求:如何按 ID 删除 Python 日志记录处理程序
- c# - Piranha cms 自动在页面类型生成器中添加页面