---
title: "Yii2.0中实现规划任务"
author: "空洞的世界"
date: "2014-11-25T11:27:37Z"
tags: ["Cron", "控制台"]
categories: ["编程语言"]
slug: "yii2-0"
draft: false
lastmod: "2014-12-01T09:53:57Z"
id: 2160021
url: "https://happymc.iteye.com/blog/2160021"
---

1.在 console/controllers 文件夹下创建一个把握器


```java
<?php
namespace console\controllers;
use yii\console\Controller;
/**

 * Test controller

 */

class TestController extends Controller {

    public function actionIndex（） {

        echo "runnning success";

    }
   //参数测试
   public function actionSend（$name） {

        echo "welcome to  " . $name;

    }

}
?>
```


注：
（1）namespace console\controllers;必须有
（2）这个把握器该当应用号令行把握器的定名空间
     use yii\console\Controller;

2.如何运行

我在 windows 下应用如式格式运行

D:\xampp\htdocs\yii2>d:\xampp\php\php yii test
result :runnning success


3.如何传递参数

在 windows 中测试如下

D:\xampp\htdocs\yii2>d:\xampp\php\php yii test/send xiaoma

result:welcome to xiaoma