当前位置:网站首页>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
边栏推荐
- The detailed page returns to the list and retains the original position of the scroll bar
- Recoverable fuse characteristic test
- Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
- Starting from 1.5, build a micro Service Framework - call chain tracking traceid
- Cf:c. the third problem
- 2020.2.13
- SSH login is stuck and disconnected
- 伦敦银走势中的假突破
- Nmap: network detection tool and security / port scanner
- Redis' cache penetration, cache breakdown, cache avalanche
猜你喜欢
Mlsys 2020 | fedprox: Federation optimization of heterogeneous networks
How to extract MP3 audio from MP4 video files?
Five challenges of ads-npu chip architecture design
View class diagram in idea
Leetcode study - day 35
Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
vSphere实现虚拟机迁移
Cf:h. maximum and [bit operation practice + K operations + maximum and]
Who knows how to modify the data type accuracy of the columns in the database table of Damon
Study diary: February 13, 2022
随机推荐
Leetcode 剑指 Offer 59 - II. 队列的最大值
JMeter BeanShell的基本用法 一下语法只能在beanshell中使用
Zhuhai's waste gas treatment scheme was exposed
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
Test de vulnérabilité de téléchargement de fichiers basé sur dvwa
Hundreds of lines of code to implement a JSON parser
Modify the ssh server access port number
cf:C. The Third Problem【关于排列这件事】
Novice entry depth learning | 3-6: optimizer optimizers
Why can't mathematics give machine consciousness
程序员搞开源,读什么书最合适?
servlet(1)
File upload vulnerability test based on DVWA
现货白银的一般操作方法
DD's command
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
MCU通过UART实现OTA在线升级流程
Getting started with devkit
朝招金安全吗 会不会亏损本金
Netease smart enterprises enter the market against the trend, and there is a new possibility for game industrialization