在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