yuchao 发表于 2018-2-11 12:08:23


            本文实例讲述了Yii实现Command任务处理的方法。分享给大家供大家参考,具体如下:
1.配置,执行任务所需要的组件
任务配置文件:/protected/config/console.php
配置方法跟配置main文件差不多
dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application',
// application components
// 自动载入的模型和组件类
'import'=>array(
      'application.models.*',//载入"application/models/"文件夹下的所有模型类
      'application.components.*',//载入"application/components/"文件夹下的所有应用组件类
      'application.extensions.*',//载入"application/extensions/"文件夹下的所有应用组件类
),
'components'=>array(
      // uncomment the following to use a MySQL database
      'db'=>array(
          'connectionString' => 'mysql:host=localhost;dbname=dbname',//连接mysql数据库
          'emulatePrepare' => true,
          'username' => 'root',//MySQL数据库用户名
          'password' => '123456',//MySQL数据库用户密码
          'charset' => 'utf8',//MySQL数据库编码
          'tablePrefix' => 'zd_', //MySQL数据库表前缀
          'enableProfiling'=>true,
          'enableParamLogging'=>true,
      ),
      //加载Email组件
      'mailer' => array(
          'class'   => 'application.extensions.mailer.EMailer',
      ),
),
);
页: [1]
查看完整版本: Yii实现Command任务处理的方法详解