Understanding Yii CConsoleApplicationOn 2 minutes
One can write a PHP script to do all that. The difficulty here is making the scripts interact with your application. This could be in the area of accessing resources used by your web application. To overcome this, Yii provides an object-oriented console enabled framework making it easy to interacts with you web applications. The base class for this framework is the CConsoleApplication. CConsoleApplication together with
CWebApplication share the same base class
CApplication by providing functionalities specific to console requests. In particular, it deals with console requests through a command-based approach.
If you recall from our CApplication discussion, I mentioned one important method
processRequest(),where the actual request processing work is done. The implementation of this method is one area where CConsoleApplication differs from CWebApplication. The user requests for
CConsoleApplications have different format from normal web request made to a CWebApplication. The format for console request is
yiic <command-name> <action-name> --option1=value --option2=value2
The following properties are defined by the
commandMap property public array $commandMap; //mapping from command name to command configurations. commandPath property public string getCommandPath() public void setCommandPath(string $value) //the directory that contains the command classes. Defaults //to 'protected/commands'. commandRunner property read-only public CConsoleCommandRunner getCommandRunner() Returns the command runner.
CConsoleApplication responds to request using the
CConsoleCommand. You can think of
CConsoleCommand as the console version of
CController. It passes the console request and dispatches it to the appropriate action.