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,虽然是国外的开发者搞的,但是它的作者是华人,这才是让我 ...
随机推荐
- LeftoverDataException,依赖包,apache license 2.0
1. poi3.9 LeftoverDataException org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: ...
- FTP的安装配置使用
///////////////////////////////FTP///////////////////////////////////////////////////写在前面:在linux 环境下 ...
- 论Spark高手是怎样炼成的
SPARK J大数据的处理怎么能变快一点,答案是请用spark,因为它是基于内存的,可以有效减少数据的落地次数.Spark性能超过Hadoop百倍,从多迭代批量处理出发,兼收并蓄数据仓库.流处理和图计 ...
- JQuery中选择元素的方法:
document.getElementById('div1');document.getElementsByTagName('div');getByClass(document,'box'); $(' ...
- java中的Properties
Properties类继承自HashTable类并实现了Map接口,也是使用一种键值对的形式来保存属性集.不过Properties有特殊的地方,就是它的键和值都是字符串类型. Properties中的 ...
- DDOS 攻击工具
DDOS 攻击工具 使用github上的DDOS攻击工具 https://github.com/Ha3MrX/DDos-Attack 将python脚本拷贝到主机,使用 chmod +x ddos- ...
- 遍历jsonArray和jsonObject
遍历jsonArray String str = "[{name:'a',value:'aa'},{name:'b',value:'bb'},{name:'c',value:'cc'}]&q ...
- Hash算法-CityHash算法
cityhash系列字符串散列算法是由著名的搜索引擎公司Google 发布的 (http://www.cityhash.org.uk/). Google发布的有两种算法:cityhash64 与 ci ...
- Android开发调试中遇到的Waiting for HOME解决方案
显示问题如图: 基本解决思路:在AVD里面单独启动运行一次模拟器,然后尝试运行程序,基本会解决这个问题.
- CSS: Flexbox
Use flexbox to create a responsive website, containing a flexible navigation bar and flexible conten ...