最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Yii實(shí)現(xiàn)Command任務(wù)處理的方法詳解

 更新時(shí)間:2016年07月14日 09:59:28   作者:dreamzml  
這篇文章主要介紹了Yii實(shí)現(xiàn)Command任務(wù)處理的方法,結(jié)合實(shí)例形式分析了Yii配置、加載及使用Command任務(wù)處理的步驟與相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了Yii實(shí)現(xiàn)Command任務(wù)處理的方法。分享給大家供大家參考,具體如下:

1.配置,執(zhí)行任務(wù)所需要的組件

任務(wù)配置文件:/protected/config/console.php

配置方法跟配置main文件差不多

<?php
// 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
  // 自動(dòng)載入的模型和組件類
  'import'=>array(
      'application.models.*',//載入"application/models/"文件夾下的所有模型類
      'application.components.*',//載入"application/components/"文件夾下的所有應(yīng)用組件類
      'application.extensions.*',//載入"application/extensions/"文件夾下的所有應(yīng)用組件類
  ),
  'components'=>array(
      // uncomment the following to use a MySQL database
      'db'=>array(
          'connectionString' => 'mysql:host=localhost;dbname=dbname',//連接mysql數(shù)據(jù)庫
          'emulatePrepare' => true,
          'username' => 'root',//MySQL數(shù)據(jù)庫用戶名
          'password' => '123456',//MySQL數(shù)據(jù)庫用戶密碼
          'charset' => 'utf8',//MySQL數(shù)據(jù)庫編碼
          'tablePrefix' => 'zd_', //MySQL數(shù)據(jù)庫表前綴
          'enableProfiling'=>true,
          'enableParamLogging'=>true,
      ),
      //加載Email組件
      'mailer' => array(
          'class'   => 'application.extensions.mailer.EMailer',
      ),
  ),
);

2.任務(wù)文件

放在 /protected/commands/ 文件目錄下繼承 CConsoleCommand 基類的為任務(wù)文件 命名方法為   任務(wù)名稱+Command

例如 GoCommand.php

<?php
/**
 * 自動(dòng)運(yùn)行文件
 */
class GoCommand extends CConsoleCommand
{
  /**
   * 死循環(huán)輸出
   */
  public function run(){
    for($i=1;$i>0;$i++){
      self::echoWord($i);
      sleep(2);//休眠2秒
      //跳出
      if(i==500){
        break;
      }
    }
  }
  /**
   * 輸出hollo word
   */
  public function echoWord($i){
    echo "hollo word --$i\n";
  }
}

3.執(zhí)行任務(wù)

打開命令行工具,進(jìn)入項(xiàng)目的/protected 目錄下 輸入yiic命令即出現(xiàn)提示,提示列表顯示剛才寫的任務(wù)文件

E:\project\app\protected>yiic
Yii command runner (based on Yii v1.1.12)
Usage: E:\zeee\zyd\protected\yiic.php <command-name> [parameters...]
The following commands are available:
- go
- mailqueue
- message
- migrate
- shell
- webapp
To see individual command help, use the following:

執(zhí)行命令 yiic go 可實(shí)現(xiàn)任務(wù)處理

更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

石屏县| 睢宁县| 扎赉特旗| 建始县| 抚远县| 清水县| 丹阳市| 进贤县| 沙雅县| 云林县| 临江市| 定襄县| 柳州市| 天峻县| 大渡口区| 鄂托克旗| 区。| 甘肃省| 哈密市| 五莲县| 通榆县| 五峰| 鄢陵县| 丹江口市| 贵德县| 汤原县| 阿拉善盟| 新安县| 茶陵县| 卢湾区| 马边| 荥经县| 蓝山县| 南漳县| 东乡| 项城市| 蒲城县| 柳州市| 临江市| 法库县| 无为县|