当前位置:网站首页>yii中console方法调用,yii console定时任务
yii中console方法调用,yii console定时任务
2022-07-06 01:14:00 【gusijin】
yii除了用于构建 Web 应用程序的丰富功能,Yii 中也有一个拥有丰富功能的控制台, 它们主要用于创建网站后台处理的任务。
控制台应用程序的结构非常类似于 Yii 的一个 Web 应用程序。 它由一个或多个 yii\console\Controller 类组成,它们在控制台环境下通常被称为“命令”。 每个控制器还可以有一个或多个动作,就像 web 控制器。
你可以通过运行 yii 脚本,在位于仓库的基本目录中运行它。
1、定时任务编写
下载 Yii 框架后,可以看到有个 console 目录,里面有完整的目录结构:配置文件、控制器、模型等

2、新建 TestController.php 文件
<?php
namespace console\controllers;
use yii\console\Controller;
class TestController extends Controller
{
/** * @var 接收的参数 */
public $param;
//指定用于控制台的参数
public function options($actionID)
{
return [
'param',
];
}
/** * @name 脚本 */
public function actionDo()
{
echo $this->param.PHP_EOL;
}
}
3、运行 php yii test/do
用法
你可以使用以下语法来执行控制台控制器动作:
php yii [ --option1=value1 --option2=value2 … argument1 argument2 … ]

php yii test/do --param=123
显示:123
边栏推荐
- Synchronized and reentrantlock
- Kotlin basics 1
- Kotlin core programming - algebraic data types and pattern matching (3)
- Finding the nearest common ancestor of binary tree by recursion
- Development trend of Ali Taobao fine sorting model
- Dedecms plug-in free SEO plug-in summary
- 伦敦银走势中的假突破
- DD's command
- C language programming (Chapter 6 functions)
- Curlpost PHP
猜你喜欢

VMware Tools installation error: unable to automatically install vsock driver

How to extract MP3 audio from MP4 video files?

ORA-00030

Blue Bridge Cup embedded stm32g431 - the real topic and code of the eighth provincial competition

Leetcode study - day 35

Daily practice - February 13, 2022

What is the most suitable book for programmers to engage in open source?

基於DVWA的文件上傳漏洞測試

Condition and AQS principle

Some features of ECMAScript
随机推荐
golang mqtt/stomp/nats/amqp
Convert binary search tree into cumulative tree (reverse middle order traversal)
Is chaozhaojin safe? Will it lose its principal
logstash清除sincedb_path上传记录,重传日志数据
Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
MYSQL---查询成绩为前5名的学生
基于DVWA的文件上传漏洞测试
Cglib dynamic agent -- example / principle
False breakthroughs in the trend of London Silver
关于softmax函数的见解
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
Leetcode study - day 35
Synchronized and reentrantlock
MobileNet系列(5):使用pytorch搭建MobileNetV3并基于迁移学习训练
Obstacle detection
Lone brave man
3D模型格式汇总
Introduction to robotics I. spatial transformation (1) posture, transformation
Finding the nearest common ancestor of binary tree by recursion
Leetcode daily question solution: 1189 Maximum number of "balloons"