CakePHP: Run shell job from controller

后端 未结 6 797
难免孤独
难免孤独 2020-12-09 06:06

Is it possible to use dispatchShell from a Controller?

My mission is to start a shell job when the user has signed up.

I\'m using CakePHP 2.0

6条回答
  •  渐次进展
    2020-12-09 06:59

    I was able to run consolle from controller/action, see the example below.

    App::uses('ShellDispatcher', 'Console');
    ...
    public function aco_sync() {
        $command = '-app '.APP.' AclExtras.AclExtras aco_sync -r adminControllers -p UserAdmin';
        $args = explode(' ', $command);
        $dispatcher = new ShellDispatcher($args, false);
        if($dispatcher->dispatch()) {
            $this->Session->flash('OK');
        } else {
            $this->Session->flash('Error');
        }
        return $this->redirect(array('action' => 'index'));
    }
    

提交回复
热议问题