在YII根目录下面有个“yii”文件,这个文件就是入口。然后“commands”目录下会默认有个“hellocontroller.php”控制器文件,这个是一个demo。打开这个控制器文件,源码如下(删掉了部分注释):
<?php namespace appcommands; use yiiconsoleController; class HelloController extends Controller { /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex($message = 'hello world') { echo $message . "n"; } }
从上面可以看出,在命令行运行时,会继承console下的Controller;而一般“controllers”目录中的控制器会继承web下的Controller。
(推荐教程:yii框架)
所以在php命令行中执行yii脚本的步骤为:
1、新建一个脚本
立即学习“PHP免费学习笔记(深入)”;
在“commands”目录下面按照“HelloController.php”的格式新建一个控制器脚本文件。
2、在命令行执行脚本
在命令行敲入“php yii项目所在路径/yii 控制器名/方法名”,例如“php web/yii hello/index”或者 直接cd到yii项目根目录(我的是web/),然后”php yii hello/index”,命令如下:
php web/yii refresh-tui-cur/tui-refresh
或
php yii user-test/refresh-userinfo
更多编程相关内容,请关注php中文网yii框架栏目!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END