yii2.0在php命令行中运行的步骤

step1 找到yii2项目根目录

step2 在advanced/console/controllers下新建文件HelloController.php

<?php
namespace console\controllers;
use yii\console\Controller;
class HelloController extends Controller
{
  /**
   * This command echoes what you have entered as the message.
   * @param string $message the message to be echoed.
   */
  public function actionIndex($message = 'hello world')
  {
    echo $message . "\n";
  }
}

step3 控制台执行

php ../yii 控制器名/action名

示例:

advanced/console# php ../yii hello/index 
或者
advanced# php yii hello/index "amyflash.com"

参考:https://www.bbsmax.com/A/mo5kyrEKzw/

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>