命令行方式运行yii2程序
2015-06-04 20:44
561 查看
测试环境,yii 2.0.3版本
web访问方式,控制器放在controllers目录下 ,浏览器访问如下地址
console访问方式,控制器放在commands目录下
示例:
模板account_template.php如下
附yii配置文件读取方式
web访问方式,控制器放在controllers目录下 ,浏览器访问如下地址
http://127.0.0.1/index.php?r=[controller-name]/[method-name]
console访问方式,控制器放在commands目录下
./yii [command-name]/[method-name]
示例:
<?php namespace app\commands; use Yii; use yii\console\Controller; use app\models\Account; class CronController extends Controller { public function actionGetAccounts() { $accounts = Account::find()->all(); if(is_array($accounts)){ $data = $this->renderFile(dirname(__DIR__) . '/assets/account_template.php', ["accounts"=>$accounts], $this); echo $data; }else{ exit(-1); } } }
模板account_template.php如下
<?php foreach($accounts as $account){ echo "account=".$account->name."\n"; } ?>
附yii配置文件读取方式
config/params.php <?php return [ 'key' => 'value', 'key1' => 'value1' ]; controller,view,model使用时通过Yii::$app->params['key']获取值
相关文章推荐
- php面向对象(OOP)—__call()处理调用错误
- php面向对象(OOP)—__toString()和__clone()
- 修改.htaccess实现301重定向的几种例子
- php关于变量(二)
- php面向对象(OOP)—static和const
- phpmyadmin error Notice: Array to string conversion in libraries\Error.class.php
- PHP类的继承和接口
- Php5.5新特性 Generators详解
- PHP 变量类型中的一些问题
- PHP+Aax实现异步验证
- laravel 5中 新建的event对应的handler不能响应的问题 解决方法
- ftp服务相关配置域管理
- yii2总结
- 开源一个工作计划管理小项目
- 【转】ubuntu12.04上安装imagemagick的PHP扩展
- PHP获取当前目录
- php mcrypt CBC
- php-fpm配置
- windows 2008+IIS7+Mysql+PHP5.5 + FastCGI环境配置
- php页面添加计数器(基于数据库)