以前、cakeでのバッチをこちらのエントリーで書きましたが、今回は3系でのバッチの書き方について。
といってもほとんど同じですが・・・
ディレクトリ
src\Shell直下に置きます。
ソース
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
namespace App\Shell; use Cake\Console\Shell; class SampleShell extends Shell { public function main() { parent::initialize(); $this->out('start task'); $this->loadModel('使いたいモデル名'); $this->モデル名->メソッド名(); $this->out('end task'); } } |
起動方法
上記のソースの場合、アプリケーションのディレクトリで ./bin/cake Sample で起動できます。