Yii--command Task Processing _php Tutorial

Source: Internet
Author: User
1. Configure the components required to perform the task
Task configuration file:/protected/config/console.php
Configuration method is almost the same as configuring the main file [HTML]

The configuration for YIIC console application.
Any writable Cconsoleapplication properties can is configured here.
Return Array (
' BasePath ' =>dirname (__file__). Directory_separator. '.. ',
' Name ' = ' My Console application ',
Application components

Auto-loaded model and component classes
' Import ' =>array (
' application.models.* ',//load all model classes under the ' application/models/' folder
' application.components.* ',//load all application component classes under the ' application/components/' folder
' application.extensions.* ',//load all application component classes under the ' application/extensions/' folder
),

' Components ' =>array (
Uncomment the following to use a MySQL database
' DB ' =>array (
' connectionString ' = ' mysql:host=localhost;dbname=dbname ',//Connect MySQL Database
' Emulateprepare ' = true,
' Username ' = ' root ',//mysql database user name
' Password ' = ' 123456 ',//mysql database user password
' CharSet ' = ' UTF8 ',//mysql database encoding
' Tableprefix ' = ' zd_ ',//mysql database table prefix
' Enableprofiling ' =>true,
' Enableparamlogging ' =>true,
),
Loading the email component
' Mailer ' = Array (
' Class ' = ' Application.extensions.mailer.EMailer ',
),
),
);

The configuration for YIIC console application.
Any writable Cconsoleapplication properties can is configured here.
Return Array (
' BasePath ' =>dirname (__file__). Directory_separator. '.. ',
' Name ' = ' My Console application ',
Application components

Auto-loaded model and component classes
' Import ' =>array (
' application.models.* ',//load all model classes under the ' application/models/' folder
' application.components.* ',//load all application component classes under the ' application/components/' folder
' application.extensions.* ',//load all application component classes under the ' application/extensions/' folder
),

' Components ' =>array (
Uncomment the following to use a MySQL database
' DB ' =>array (
' connectionString ' = ' mysql:host=localhost;dbname=dbname ',//Connect MySQL Database
' Emulateprepare ' = true,
' Username ' = ' root ',//mysql database user name
' Password ' = ' 123456 ',//mysql database user password
' CharSet ' = ' UTF8 ',//mysql database encoding
' Tableprefix ' = ' zd_ ',//mysql database table prefix
' Enableprofiling ' =>true,
' Enableparamlogging ' =>true,
),
Loading the email component
' Mailer ' = Array (
' Class ' = ' Application.extensions.mailer.EMailer ',
),
),
); 2. Task file
Under the/protected/commands/file directory, inherit the Cconsolecommand base class for the task file naming method for the task name +command
e.g. gocommand.php[html]

/**
* Automatically run files
*/
Class Gocommand extends Cconsolecommand
{


/**
* Dead Loop output
*/
Public Function run () {

for ($i =1; $i >0; $i + +) {
Self::echoword ($i);
Sleep (2);//sleep 2 seconds

Jump
if (i==500) {
Break
}
}
}

/**
* Output Hollo Word
*/
Public Function Echoword ($i) {
echo "Hollo word-$i \ n";
}
}

/**
* Automatically run files
*/
Class Gocommand extends Cconsolecommand
{


/**
* Dead Loop output
*/
Public Function run () {

for ($i =1; $i >0; $i + +) {
Self::echoword ($i);
Sleep (2);//sleep 2 seconds

Jump
if (i==500) {
Break
}
}
}

/**
* Output Hollo Word
*/
Public Function Echoword ($i) {
echo "Hollo word-$i \ n";
}
}3. Performing Tasks
Opens the command line tool, enters the project the/protected directory to enter the YIIC command to appear prompts, prompts the list to display the task file which 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 is available:
-Go
-MailQueue
-Message
-Migrate
-Shell
-WebApp

To see individual 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 is available:
-Go
-MailQueue
-Message
-Migrate
-Shell
-WebApp

To see individual command help, use the following: Execute command YIIC go for task handling

http://www.bkjia.com/PHPjc/477288.html www.bkjia.com true http://www.bkjia.com/PHPjc/477288.html techarticle 1. Configure the component task profile required to perform the task:/protected/config/console.php configuration method is similar to configuring the main file [HTML]? PHP//This is the configuration for Yi ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.