首页 > 解决方案 > 如何在 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

标签: phpcakephpcakephp-2.3

解决方案


推荐阅读