Here is a step by step to show how to run command in the server with yii framework.

1. Create the web application.

yiic webapp ./myapp

2. Edit myapp/protected/config/console.php:


returnarray(
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'My Console Application', 'params'=>array(
'testparam'=>'testvalue',
),
);

3. Create myapp/protected/commands/DemoCommand.php:


<?php
class DemoCommand extends CConsoleCommand { publicfunction run($args)
{
echo"Hello! Param=".Yii::app()->params['testparam']."\n";
}
}

4. Check that yiic finds the command:

david_lee@david-desktop:~$/var/www/webapp/protected/yiic

Tip: make sure that you have the php bin in /usr/bin.

Then you will get the message as below:


Yii command runner (based on Yii v1.1.3)
Usage: ./protected/yiic <command-name> [parameters...] The following commands are available:
- demo
- message
- shell
- webapp

5. Run the command:

david_lee@david-desktop:~$ /var/www/webapp/protected/yiic demo

You will get the output:

Hello!Param=testvalue

Tip: You have to pay attention that the name of the command above: yiic demo. Please compare with the name of myapp/protected/commands/DemoCommand.php

Have fun with Yii!

Yii console 的db 如果是localhost需要修改为127.0.0.1

yii console的更多相关文章

  1. Yii console 创建命令行应用

    大家都知道PHP的程序没有进程概念,而且生命周期极短,无法实现一些定时计划或者是计划任务,今天我们看看在YII框架中如何使用计划任务创建命令行应用. 1.在 console/controllers 文 ...

  2. yii console.php 报错 Property "CConsoleApplication.theme" is not defined.

    默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...

  3. Yii2 定时任务创建(Console 任务)

    Yii2的定时任务可以有两种写法,原理都是通过服务器的定时任务去调用 1.通过调用指定的URL访问 就相当于在浏览器中访问 2.通过console调用 下面我们就来说说Console 是如何实现定时任 ...

  4. Yii应用的目录结构和入口脚本

    以下是一个通过高级模版安装后典型的Yii应用的目录结构: . ├── backend ├── common ├── console ├── environments ├── frontend ├── ...

  5. Yii源码阅读笔记(二十六)

    Application 类中设置路径的方法和调用ServiceLocator(服务定位器)加载运行时的组件的方法注释: /** * Handles the specified request. * 处 ...

  6. Yii源码阅读笔记(二十一)——请求处理流程

    Yii2请求处理流程: 首先:项目路径/web/index.php (new yii\web\Application($config))->run();//根据配置文件创建App实例,先实例化y ...

  7. Yii源码阅读笔记(三)

    接着上次的继续阅读BaseYii.php vendor/yiisoft/yii2/BaseYii.php—— public static function getRootAlias($alias)// ...

  8. yii2 ./yii command : No such file or directory

    git clone下来的yii2后台项目,由于需要执行 ./yii migrate命令.执行之后,提示 No such file or directory 我从同样为yii2 basic的./yii ...

  9. 【Yii系列】Yii2.0基础框架

    缘起 因为一个月的短暂停留,我在给朋友搞事情,所以Yii系列的文章耽搁了很长时间,现在又重拾当时的知识,给大伙好好撸下这一系列的博客 提起Yii,虽然是国外的开发者搞的,但是它的作者是华人,这才是让我 ...

随机推荐

  1. Java 正则表达式 Pattern & Matcher

    通常会有这种需求: 在文档中搜索有规律的字符串,然后进行统计或者替换.Java.util.regex包下的Pattern和Matcher这两个类提供了通过正则表达式来匹配查询,甚至替换的功能.那么我们 ...

  2. Codeforces Round #363 (Div. 2) A、B、C

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. NumPy切片和索引

    NumPy - 切片和索引 ndarray对象的内容可以通过索引或切片来访问和修改,就像 Python 的内置容器对象一样. 如前所述,ndarray对象中的元素遵循基于零的索引. 有三种可用的索引方 ...

  4. NumPy位操作

    NumPy - 位操作 下面是 NumPy 包中可用的位操作函数. 序号 操作及描述 1. bitwise_and 对数组元素执行位与操作 2. bitwise_or 对数组元素执行位或操作 3. i ...

  5. 腾讯开源的Android UI框架——QMUI Android

    各位同学,早上好,我是你们的老朋友D_clock爱吃葱花,前些天忙着发版本,最近也在看各种各样的新知识,有好多东西想写啊啊啊啊啊.嗯,先冷静捋一下,卖个关子.扯回正题,今天继续为大家推荐一个Githu ...

  6. SpringBoot:竟然has no explicit mapping for /error

    异常:This application has no explicit mapping for /error, so you are seeing this as a fallback. 出现这个异常 ...

  7. jenkins的Master/Slave模式

    一. Master/Slave模式 分担jenkins服务器的压力,任务分配到其它执行机来执行 Master:Jenkins服务器 Slave:执行机(奴隶机).执行Master分配的任务,并返回任务 ...

  8. ubuntu定时执行任务——crontab的使用

    先补上几个链接,后续再总结 #参考# http://www.cnblogs.com/kaituorensheng/p/4494321.html http://blogread.cn/it/articl ...

  9. element-ui 的el-button组件中添加自定义颜色和图标的实现方法

    这篇文章主要介绍了element-ui 的el-button组件中添加自定义颜色和图标的实现方法,目前的解决方案是:添加一个自定义全局指令,同时在element-ui源码中,加入对应的组件.需要的朋友 ...

  10. Makefile的补充学习2

    Makefile中使用通配符(1)* 若干个任意字符(2)? 1个任意字符(3)[] 将[]中的字符依次去和外面的结合匹配 还有个%,也是通配符,表示任意多个字符,和*很相似,但是%一般只用于规则描述 ...