当前位置:网站首页>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
边栏推荐
- ORA-00030
- Distributed base theory
- 毕设-基于SSM高校学生社团管理系统
- The inconsistency between the versions of dynamic library and static library will lead to bugs
- Obstacle detection
- File upload vulnerability test based on DVWA
- Mysql--- query the top 5 students
- JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
- 在产业互联网时代,将会凭借大的产业范畴,实现足够多的发展
- After 95, the CV engineer posted the payroll and made up this. It's really fragrant
猜你喜欢

ThreeDPoseTracker项目解析

Mobilenet series (5): use pytorch to build mobilenetv3 and learn and train based on migration

Condition and AQS principle

Five challenges of ads-npu chip architecture design

测试/开发程序员的成长路线,全局思考问题的问题......

Differences between standard library functions and operators

How to see the K-line chart of gold price trend?

SAP Spartacus home 页面读取 product 数据的请求的 population 逻辑

ORA-00030

Cve-2017-11882 reappearance
随机推荐
朝招金安全吗 会不会亏损本金
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
Keepalive component cache does not take effect
Questions about database: (5) query the barcode, location and reader number of each book in the inventory table
What is the most suitable book for programmers to engage in open source?
Paging of a scratch (page turning processing)
KDD 2022 | EEG AI helps diagnose epilepsy
Beginner redis
Cf:h. maximum and [bit operation practice + K operations + maximum and]
Gartner发布2022-2023年八大网络安全趋势预测,零信任是起点,法规覆盖更广
网易智企逆势进场,游戏工业化有了新可能
Four dimensional matrix, flip (including mirror image), rotation, world coordinates and local coordinates
[groovy] compile time metaprogramming (compile time method injection | method injection using buildfromspec, buildfromstring, buildfromcode)
Recursive method to realize the insertion operation in binary search tree
curlpost-php
现货白银的一般操作方法
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
[groovy] compile time metaprogramming (compile time method interception | find the method to be intercepted in the myasttransformation visit method)
记一个 @nestjs/typeorm^8.1.4 版本不能获取.env选项问题
1791. Find the central node of the star diagram / 1790 Can two strings be equal by performing string exchange only once