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,虽然是国外的开发者搞的,但是它的作者是华人,这才是让我 ...
随机推荐
- HTML5 地理定位 【来自百度应用分享平台】
百度给的地图API接口相当完善,复制过来一下,以后备用 基本使用方法: <!--引入百度地图API--> <scriptsrc="http://api.map.baidu. ...
- Python jieba 分词
环境 Anaconda3 Python 3.6, Window 64bit 目的 利用 jieba 进行分词,关键词提取 代码 # -*- coding: utf-8 -*- import jieba ...
- yii定时任务(linux)
yii写好了,计划任务,那么需要测试,测试地址大致: 我的测试文件名称:TestControllers.php, windows环境下: 我的项目在f:\www下, CMD: f:/www/ php ...
- 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 ...
- oracle数据库查看用户相关语句
1.查看所有用户: select * from dba_users; select * from all_users; select * from user_users; 2.查看用户 ...
- LeetCode OJ:Remove Nth Node From End of List(倒序移除List中的元素)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- Http权威指南(TCP连接)
1.HTTP请求的过程 世界上几乎所有的HTTP通信都是由TCP/IP承载的,当发生HTTP请求时,实际上经过了以下几个步骤: ①浏览器从请求的URL中解析主机名 ②浏览器查询这个主机名的IP地址 ③ ...
- Arcgis for Js实现graphiclayer的空间查询(续)
上文中,实现了简单的针对graphiclayer的空间查询工作,在本节,将更加详细的介绍针对graphiclayer的空间查询.首先,空间查询的方式:提供多种类型的空间查询,包括点周边.线周边.面内等 ...
- VS2017连接到中国区的Azure
1. 安装Azure Environment Select扩展 2. 选择中国区的Azure 3. 之后就可以使用中国区的账号登录了 参考链接:https://docs.azure.cn/zh-cn/ ...
- [转载] PHP升级导致系统负载过高问题分析
原文:http://chuansongme.com/n/797172 背景 据XX部门兄弟反应, 其在将PHP从5.3.8 升级到5.5.13 时, 开始运行正常, 运行一段时间后, 系统负载变高,达 ...