yii console
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的更多相关文章
- Yii console 创建命令行应用
大家都知道PHP的程序没有进程概念,而且生命周期极短,无法实现一些定时计划或者是计划任务,今天我们看看在YII框架中如何使用计划任务创建命令行应用. 1.在 console/controllers 文 ...
- yii console.php 报错 Property "CConsoleApplication.theme" is not defined.
默认配置的话,是不会出现这个错误的,应该是有人为修改了 yiic.php 这个文件,本来是 $config 载入的应该是 console.php ,人为修改后载入了 main.php 这个配置文件了 ...
- Yii2 定时任务创建(Console 任务)
Yii2的定时任务可以有两种写法,原理都是通过服务器的定时任务去调用 1.通过调用指定的URL访问 就相当于在浏览器中访问 2.通过console调用 下面我们就来说说Console 是如何实现定时任 ...
- Yii应用的目录结构和入口脚本
以下是一个通过高级模版安装后典型的Yii应用的目录结构: . ├── backend ├── common ├── console ├── environments ├── frontend ├── ...
- Yii源码阅读笔记(二十六)
Application 类中设置路径的方法和调用ServiceLocator(服务定位器)加载运行时的组件的方法注释: /** * Handles the specified request. * 处 ...
- Yii源码阅读笔记(二十一)——请求处理流程
Yii2请求处理流程: 首先:项目路径/web/index.php (new yii\web\Application($config))->run();//根据配置文件创建App实例,先实例化y ...
- Yii源码阅读笔记(三)
接着上次的继续阅读BaseYii.php vendor/yiisoft/yii2/BaseYii.php—— public static function getRootAlias($alias)// ...
- yii2 ./yii command : No such file or directory
git clone下来的yii2后台项目,由于需要执行 ./yii migrate命令.执行之后,提示 No such file or directory 我从同样为yii2 basic的./yii ...
- 【Yii系列】Yii2.0基础框架
缘起 因为一个月的短暂停留,我在给朋友搞事情,所以Yii系列的文章耽搁了很长时间,现在又重拾当时的知识,给大伙好好撸下这一系列的博客 提起Yii,虽然是国外的开发者搞的,但是它的作者是华人,这才是让我 ...
随机推荐
- FM算法 的总结
FM的总结: 1.FM算法与线性回归相比增加了特征的交叉.自动选择了所有特征的两两组合,并且给出了两两组合的权重. 2.上一条所说的,如果给两两特征的组合都给一个权重的话,需要训练的参数太多了.比如我 ...
- 腾讯开源手游热更新方案,Unity3D下的Lua编程
原文:http://www.sohu.com/a/123334175_355140 作者|车雄生 编辑|木环 腾讯最近在开源方面的动作不断:先是微信跨平台基础组件Mars宣布开源,腾讯手游又于近期开源 ...
- phpexcel: 数据导出
// 设置列名最多40个 $cols = array( "A", "B", "C", "D", "E" ...
- yii2定时任务不执行,报错PHP date调用警告:It is not safe to rely on the system's timezone settings
It is not safe to rely on the system's timezone settings 在写php程序中有时会出现这样的警告:PHP Warning: date(): It ...
- Referenced file contains errors (http://www.springframework.org/schema/aop/spring-aop-3.0.xsd). For more information, right click on the message in th
XML code<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC &q ...
- 在js中,ajax放在for中,ajax获取得到的变量有误
先看代码 for(var i=0;i<tds.length;i++){ mui.ajax(url+'api/client/gifts/isSigned', {data :{ sqId:" ...
- Qt类型转换
(转自:http://qimo601.iteye.com/blog/1260479) 1.char * 与 const char *的转换 char *ch1="hello11"; ...
- 配置 Web 组件服务器 IIS 证书
用 IIS 6 配置 Web 组件证书(对于 Windows Server 2003) 使用 IIS 管理器向 Web 组件服务器分配证书.对合并池配置中的 Standard Edition ...
- 关于Object类的equals方法和hashCode方法
关于Object类的equals的特点,对于非空引用: 1.自反性:x.equals(x) return true : 2.对称性:x.equals(y)为true,那么y.equals(x)也为tr ...
- Linux SVN 切换用户
1. 临时切换 在所有命令前强制加上--username 和 --password 例如:svn up --username zhangsan --password 123456 2. 永久切 ...