美文网首页
命令行方式运行yii2程序

命令行方式运行yii2程序

作者: zlchen | 来源:发表于2021-07-19 16:05 被阅读0次

测试环境,yii 2.0.42.1版本

1、web访问方式,控制器放在controllers目录下 ,浏览器访问如下地址

http://127.0.0.1/index.php?r=[controller-name]/[method-name]

2、console访问方式,控制器放在commands目录下

./yii [command-name]/[method-name]

[root@iZbp1ff38278eoy1t5paezZ basic]# ./yii hello/index
hello world
[root@iZbp1ff38278eoy1t5paezZ basic]# ./yii hello/index hello-yii2.0
hello-yii2.0
[root@iZbp1ff38278eoy1t5paezZ basic]# ./yii hello/yii_version
2.0.42.1
// commands/HelloController.php
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace app\commands;

use yii\console\Controller;
use yii\console\ExitCode;

/**
 * This command echoes the first argument that you have entered.
 *
 * This command is provided as an example for you to learn how to create console commands.
 *
 * @author Qiang Xue <qiang.xue@gmail.com>
 * @since 2.0
 */
class HelloController extends Controller
{
    /**
     * This command echoes what you have entered as the message.
     * @param string $message the message to be echoed.
     * @return int Exit code
     */
    public function actionIndex($message = 'hello world')
    {
        echo $message . "\n";

        return ExitCode::OK;
    }
    //  V2.0.42.1
    public function actionYiiVersion()
    {
        echo \Yii::getVersion(). "\n";
        
        return ExitCode::OK;
    }
}

相关文章

  • 命令行方式运行yii2程序

    测试环境,yii 2.0.42.1版本 1、web访问方式,控制器放在controllers目录下 ,浏览器访问如...

  • 2.C++程序设计——命令行参数

    以命令行方式运行程序 notepad sample.txtnotepad程序如何得知,用户在以命令行方式运行它的时...

  • Python基础教程:教你如何在交互式环境中执行Python程序

    相信接触过Python的伙伴们都知道运行Python脚本程序的方式有多种,目前主要的方式有:交互式环境运行、命令行...

  • Python基础教程:教你如何在交互式环境中执行Python程序

    相信接触过Python的伙伴们都知道运行Python脚本程序的方式有多种,目前主要的方式有:交互式环境运行、命令行...

  • appium安装(windows)和启动

    两种安装方式windows 1.通过npm来安装 这种方式是命令行的方式。 使用范围:主要用来通过程序来运行,启动...

  • 2019-02-28

    一、运行train程序 运行程序的命令行: 记得先转到当前目录下 再执行如下命令行: 注意端口名称与自己分配的端口...

  • 环境变量

    环境变量 为什么系统要有个 PATH 变量?原因就是为了能够脱离程序的绝对路径以命令行方式来运行程序,这样使得程序...

  • ☆CUDA 出错 debug 注意点

    运行程序之前,在运行程序的命令行窗口,执行 export CUDA_LAUNCH_BLOCKING=1 以获得准确...

  • NS3基本命令学习

    脚本运行 日志设置 可以在程序中给程序设置日志级别 程序外export命令设置 使用命令行参数(当次运行有效) 使...

  • 笨办法学Python ex12

    提示别人 输入: 运行: 附加题 1.在命令行界面下运行你的程序,然后在命令行输入 pydoc raw_input...

网友评论

      本文标题:命令行方式运行yii2程序

      本文链接:https://www.haomeiwen.com/subject/mqchmltx.html