CakePHP: Run shell job from controller

后端 未结 6 793
难免孤独
难免孤独 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:56

    In CakePHP-3 you can dispatch shells from the controller & do it almost the same as in CakePHP-2. The documentation does not mention this.

    // in your controller:
    $shell = new \Cake\Console\Shell;
    $shell->dispatchShell('shell_class param1 param2');
    // or how the docs suggest
    $shell->dispatchShell('shell_class', 'param1', 'param2');
    

    Beware of stdout & stderr in unit tests.

    Dispatching a shell turns on stdout and stderr logging with ConsoleLogger, and will give you all the logging in your console if you have something like the code snippet above in code that you are testing from phpunit.

提交回复
热议问题