Creating CLI commands
Yii has a good command-line support and allows creating reusable console commands. Console commands are faster to create than web GUIs. If you need to create some kind of utility for your application that will be used by developers or administrators, console commands are the right tool.
To show how to create a console command we'll create a simple command that will clean up various things such as cache, temp directories, and so on.
Getting ready
Create a fresh Yii application using yiic webapp.
How to do it...
Create
protected/extensions/clean_command/ECleanCommand.php:<?php class ECleanCommand extends CConsoleCommand { public $webRoot; public function actionCache() { $cache=Yii::app()->getComponent('cache'); if($cache!==null){ $cache->flush(); echo "Done.\n"; } else { echo "Please configure cache component.\n"; } } public function actionAssets() { if(empty($this->webRoot...