本文實例講述了thinkphp3.x自定義Action、Model及View的實現方法。分享給大家供大家參考,具體如下:
1、在xmall/Lib/Action中創建文件TestAction.class.php
class TestAction extends Action{
function index(){
$this->display("test");
}
}
2、在xmall/tpl下創建default文件夾,在default下創建Test文件夾,在Test下創建test.html模版文件;
3、執行URL:http://localhost/xmall/index.php/Test/index就會出現test.html頁面的內容
4、在操作過程中出現的錯誤:
(1) URL中的Test的T要大寫;
(2) Display不需要提供文件的擴展名,默認為index
5、注意事項:
(1) 為方便調試,應在index.php入口文件中添加
define("APP_DEBUG",true);
(2) 最好在配置文件(xmall/Conf/config.php)中指定默認模版:'DEFAULT_THEME' => 'default'
6、在xmall/lib/Model下創建文件UserModel.class.php
class UserModel extends Model{
function test(){
return "123456";
}
}
7、在xmall/Lib/Action/TestAction.class.php添加新方法
public function test(){
$m=D("User");
echo $m->test();
}
8、執行URL:http://localhost/xmall/index.php/Index/test,頁面輸出123456
9、注:Model文件名要與model的名稱一直,并且在調用時區分大小寫;
在xmall/conf/config.php中添加'URL_CASE_INSENSITIVE' =>true,//URL不區分大小寫
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。