Yii -- Command task processing. 1. configure the component task configuration file required to execute the task: the configuration method of protectedconfigconsole. php is similar to that of configuring the main file [html]? PhpThisistheconfigurationforyi 1. configure the components required to execute the task.
Task configuration file:/protected/config/console. php
The configuration method is similar to the configuration of the main file [html]
// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
Return array (
'Basepath' => dirname (_ FILE _). DIRECTORY_SEPARATOR .'..',
'Name' => 'My Console application ',
// Application components
// Automatically loaded models and component classes
'Import' => array (
'Application. models. * ', // load all model classes in the "application/models/" folder
'Application. components. * ', // load all application component classes in the "application/components/" folder
'Application. extensions. * ', // load all application component classes in the "application/extensions/" folder
),
'Components' => array (
// Uncomment the following to use a MySQL database
'DB' => array (
'Connectionstring' => 'MySQL: host = localhost; dbname = dbname', // connect to the mysql database
'Default' => true,
'Username' => 'root', // MySQL database username
'Password' => '000000', // MySQL database user password
'Charset' => 'utf8', // MySQL database encoding
'Tableprefix' => 'zd _ ', // MySQL database table prefix
'Enablesprofiling' => true,
'Enablesparamlogging' => true,
),
// Load the Email component
'Mailer' => array (
'Class' => 'application. extensions. mailer. EMailer ',
),
),
);
// This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
Return array (
'Basepath' => dirname (_ FILE _). DIRECTORY_SEPARATOR .'..',
'Name' => 'My Console application ',
// Application components
// Automatically loaded models and component classes
'Import' => array (
'Application. models. * ', // load all model classes in the "application/models/" folder
'Application. components. * ', // load all application component classes in the "application/components/" folder
'Application. extensions. * ', // load all application component classes in the "application/extensions/" folder
),
'Components' => array (
// Uncomment the following to use a MySQL database
'DB' => array (
'Connectionstring' => 'MySQL: host = localhost; dbname = dbname', // connect to the mysql database
'Default' => true,
'Username' => 'root', // MySQL database username
'Password' => '000000', // MySQL database user password
'Charset' => 'utf8', // MySQL database encoding
'Tableprefix' => 'zd _ ', // MySQL database table prefix
'Enablesprofiling' => true,
'Enablesparamlogging' => true,
),
// Load the Email component
'Mailer' => array (
'Class' => 'application. extensions. mailer. EMailer ',
),
),
); 2. task file
Put it in the/protected/commands/file directory, inherit the CConsoleCommand base class, and name the task file as the task name + Command
For example, GoCommand. php [html]
/**
* Automatically run the file
*/
Class GoCommand extends CConsoleCommand
{
/**
* Endless loop output
*/
Public function run (){
For ($ I = 1; $ I> 0; $ I ++ ){
Self: echoWord ($ I );
Sleep (2); // sleep for 2 seconds
// Jump out
If (I = 500 ){
Break;
}
}
}
/**
* Output the hollo word
*/
Public function echoWord ($ I ){
Echo "Holo word -- $ I \ n ";
}
}
/**
* Automatically run the file
*/
Class GoCommand extends CConsoleCommand
{
/**
* Endless loop output
*/
Public function run (){
For ($ I = 1; $ I> 0; $ I ++ ){
Self: echoWord ($ I );
Sleep (2); // sleep for 2 seconds
// Jump out
If (I = 500 ){
Break;
}
}
}
/**
* Output the hollo word
*/
Public function echoWord ($ I ){
Echo "Holo word -- $ I \ n ";
}
} 3. execute the task
Open the command line tool and enter the/protected Directory of the project and enter the yiic command to display the prompt. the prompt list displays the task file you just wrote [html]
E: \ project \ app \ protected> yiic
Yii command runner (based on Yii v1.1.12)
Usage: E: \ zeee \ zyd \ protected \ yiic. php [Parameters...]
The following commands are available:
-Go
-Mailqueue
-Message
-Migrate
-Shell
-Webapp
To see inpidual command help, use the following:
E: \ project \ app \ protected> yiic
Yii command runner (based on Yii v1.1.12)
Usage: E: \ zeee \ zyd \ protected \ yiic. php [Parameters...]
The following commands are available:
-Go
-Mailqueue
-Message
-Migrate
-Shell
-Webapp
To see inpidual command help, use the following: execute the command yiic go To implement task processing
Refer task configuration file:/protected/config/console. php configuration method is similar to configuring the main file [html]? Php // This is the configuration for yi...