yii2 console unknown命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yii2 console unknown命令相关的知识,希望对你有一定的参考价值。
试图在控制器_googleanalytics
中运行函数ProcessingController
,但收到错误:
未知的命令
command
:
./yii processing/_googleanalytics '2017-02-27' '2017-02-27'
controller
路径:
/console/controllers/
action
public function _googleanalytics($start, $finish) {...
controller
namespace consolecontrollers;
class ProcessingController extends Controller
{...
/console/config/main.php
return [
'id' => 'app-console',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'controllerNamespace' => 'consolecontrollers',
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'controllerMap' => [
'fixture' => [
'class' => 'yiiconsolecontrollersFixtureController',
'namespace' => 'commonfixtures',
],
],
'components' => [
'log' => [
'targets' => [
[
'class' => 'yiilogFileTarget',
'levels' => ['error', 'warning','info'],
'exportInterval' => 1,
],
[
'class' => 'yiilogFileTarget',
'levels' => ['info'],
'exportInterval' => 1,
'logVars' => [],
'categories' => ['calls'],
'logFile' => '@app/runtime/logs/calls.log',
'maxFileSize' => 1024 * 2,
'maxLogFiles' => 20,
],
],
],
],
'modules'=>[
'user-management' => [
'class' => 'webvimarkmodulesUserManagementUserManagementModule',
'controllerNamespace'=>'vendorwebvimarkmodulesUserManagementcontrollers', // To prevent yii help from crashing
],
'googleanalytics' => [
'class' => 'consolemodulesgoogleanalyticsModule',
]
],
'params' => $params,
];
我做错了什么?
您需要制作一个action
来通过控制台/终端访问它,就像我们通过浏览器访问操作一样。
例如,如果我在Test Controller
目录中创建如下所示的console/controllers
<?php
namespace consolecontrollers;
class TestController extends yiiconsoleController{
public function actionIndex($param1,$param2){
echo "
Index";
echo "
$param1 $param2
";
}
public function actionMango(){
echo "
Mango";
}
}
然后键入./yii
并按Enter键将显示所有可用的默认命令以及最后的以下内容。
This is Yii version 2.0.14.1.
The following commands are available:
....
...
- test
test/index (default)
test/mango
这意味着它将控制器内的所有操作注册为命令,如果在终端中写入以下命令,
./yii test/index omer aslam
它会显示输出
Index
omer aslam
其中omer
和aslam
是传递给函数的2个参数。
所以你只需要将关键字action
添加到你的函数名称我建议根据约定使用动作名称,更改函数
public function _googleanalytics($start, $finish) {
至
public function actionGoogleanalytics($start, $finish) {
然后通过访问它
./yii process/googleanalytics 2017-02-27 2017-02-27
你可以用引号括起来,但是没有必要在单独的参数之间添加一个空格。
希望能帮助到你
以上是关于yii2 console unknown命令的主要内容,如果未能解决你的问题,请参考以下文章
yii2 为啥数组存个数据会报 setting unknown property
YII2安装中遇到的错误解决Calling unknown method: yiiwebUrlManager::addRules()
Android Parcelable反序列化报错笔记:java.lang.RuntimeException: Unmarshalling unknown type code at offset(代码片