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,虽然是国外的开发者搞的,但是它的作者是华人,这才是让我 ...
随机推荐
- yii2:frontend/frontactoin curl生成
yii2:frontend/frontactoin curl生成 想要覆写已存在文件,选中 “overwrite” 下的复选框然后点击 “Generator”.如果是新文件,只点击 “Generato ...
- python脚本3_输入若干个整数打印出最大值
#输入若干个整数,打印出最大值 # m = int(input('Input first number >>>')) while True: c = input('Input a n ...
- eclipse配置tomcat运行项目访问不加项目名
- day5-随机数相关:random模块&string模块
一.概述 随机数在程序设计中的属于比较基础的内容,主要用于验证场景(如验证码,生成账号对应的密码等),今天结合random模块和string模块来谈谈python中随机数那些事儿. 二.随机数实现相关 ...
- html5新增语义化标签
注意:body.section.nav 需要h1-h6. div.header则不需要. 1):<article> 显示一个独立的文章内容. 例如一篇完整的论坛帖子,一则网站新闻,一篇博客 ...
- windows钩子
(转自:http://wenku.baidu.com/view/5d41fdbec77da26925c5b08d.html) Windows系统是建立在事件驱动的机制上的,说穿了就是整个系统都是通过消 ...
- C3P0使用详解
定义: C3P0是一个开源的JDBC连接池,目前使用它的开源项目有Hibernate,Spring等. 数据库连接池的基本思想就是为数据库连接建立一个"缓冲池".预先在缓冲池中放入 ...
- Spring Batch教程
Spring Batch系列总括 : http://www.cnblogs.com/gulvzhe/archive/2011/12/20/2295090.html
- linux使用virtualenv构建虚拟环境,requirement.txt记录包版本
virtualenv介绍: virtualenv把是一个把python应用隔离在一个虚拟环境中的工具.网上的例子较多,这里重点讲述怎么使用virtualenv来激活一个虚拟环境,并且记录虚拟环境中所依 ...
- GIS的核心价值——服务
注:本观点仅代表个人观点,与任何人员或者组织无任何关系,如有雷同或者相似之处,只能说明我们对GIS的理解相同,无抄袭之嫌. 写这个题目,源于前两天接到的一个电话面试时候问道的一个面试题.当时, ...