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 t
in order to call shell from your controller function you need to do this in your controller function :
namespace App\Controller;
use App\Controller\AppController;
use Cake\Console\ShellDispatcher; //use this shell dispacher
/**
* Example Controller
*
*/
class ExampleController extends AppController
{
/**
* Index method
*
* @return \Cake\Network\Response|null
*/
public function index()
{
$shell = new ShellDispatcher(); //create object of your Shell Dispatcher
$output = $shell->run(['cake', 'foo']); //here foo is your shell name
if (0 === $output) {
$this->Flash->success('Success from shell command.');
} else {
$this->Flash->error('Failure from shell command.');
}
return $this->redirect('/');
}
}
hope this answer your question, if any problem leave a comment.
thank you.