PHP command to pass parameters, Yii command $ args source

Source: Internet
Author: User
Tags php file php code yii

When using the YII Framework, a yiic command tool is generated in the protected folder after the framework is structured. Here you can use the YII built-in command, first, you need to create a command php file under commands. The file name format is as follows: DemoCommand. php

The code is as follows:

The code is as follows: Copy code

Class DemoCommand extends CConsoleCommand {
// Number of processes
Private $ thread = 10;
Public function run ($ args)
$ Demos = $ this-> getDemo ($ args [0]);
Echo "start ******************************** n ". date ('Y-m-d H: I: s ');
Foreach ($ demos as $ demo)
$ This-> getTest ($ demo );
Echo "running is completed ******************************* n ". date ('Y-m-d H: I: s ');
Public function getTest ()
// The code you want to execute here is It can be any php code, including SQL.
Public function getDemo ($ index)
// The code you want to execute can be any php code, including SQL.
Return $ index;

I don't know if you have any questions. Have you noticed a variable $ args in the run method and called $ args [0] in the run method? $ args must be an array. But where does $ args come from? In this case, we need to pass the php command line parameters, for example, H: workspace> php test. php arg1 arg2.
I don't know much about this. Let's take a look at the parameters used to execute command commands in YII. It is a scheduled command execution program in Linux.
0 15, 11, 21 ** cd/file path/&/usr/local/php/bin/php yiic demo 0>/usr/home/test. log [the preceding number indicates that the command is executed at three o'clock P.M. on the first, 11th, and 21st of each month]
Run the command in protected of Yii:/usr/local/php/bin/php yiic create_excellenthall 0. Have you noticed the last 0? This is passed by $ args. You can replace it with any key value in the array.
The description should not be very professional. I hope it can help people who need it!

Related Article

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: 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.