《PHP實(shí)例:thinkphp3.x自定義Action、Model及View的簡單實(shí)現(xiàn)方法》要點(diǎn):
本文介紹了PHP實(shí)例:thinkphp3.x自定義Action、Model及View的簡單實(shí)現(xiàn)方法,希望對(duì)您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:thinkphp教程
本文實(shí)例講述了thinkphp3.x自定義Action、Model及View的實(shí)現(xiàn)辦法.分享給大家供大家參考,具體如下:PHP學(xué)習(xí)
1、在xmall/Lib/Action中創(chuàng)建文件TestAction.class.phpPHP學(xué)習(xí)
class TestAction extends Action{ function index(){ $this->display("test"); } }
2、在xmall/tpl下創(chuàng)建default文件夾,在default下創(chuàng)建Test文件夾,在Test下創(chuàng)建test.html模版文件;PHP學(xué)習(xí)
3、執(zhí)行URL:http://localhost/xmall/index.php/Test/index就會(huì)出現(xiàn)test.html頁面的內(nèi)容PHP學(xué)習(xí)
4、在操作過程中出現(xiàn)的錯(cuò)誤:PHP學(xué)習(xí)
(1) URL中的Test的T要大寫;PHP學(xué)習(xí)
(2) Display不需要提供文件的擴(kuò)展名,默認(rèn)為indexPHP學(xué)習(xí)
5、注意事項(xiàng):PHP學(xué)習(xí)
(1) 為方便調(diào)試,應(yīng)在index.php入口文件中添加PHP學(xué)習(xí)
define("APP_DEBUG",true);
(2) 最好在配置文件(xmall/Conf/config.php)中指定默認(rèn)模版:'DEFAULT_THEME' => 'default'PHP學(xué)習(xí)
6、在xmall/lib/Model下創(chuàng)建文件UserModel.class.phpPHP學(xué)習(xí)
class UserModel extends Model{ function test(){ return "123456"; } }
7、在xmall/Lib/Action/TestAction.class.php添加新辦法PHP學(xué)習(xí)
public function test(){ $m=D("User"); echo $m->test(); }
8、執(zhí)行URL:http://localhost/xmall/index.php/Index/test,頁面輸出123456PHP學(xué)習(xí)
9、注:Model文件名要與model的名稱一直,并且在調(diào)用時(shí)區(qū)分大小寫;PHP學(xué)習(xí)
在xmall/conf/config.php中添加'URL_CASE_INSENSITIVE' =>true,//URL不區(qū)分大小寫PHP學(xué)習(xí)
PS:這里推薦幾款本站的格式化美化工具,相信大家在以后的開發(fā)中能夠用得上:PHP學(xué)習(xí)
php代碼在線格式化美化工具:
ode/phpformatPHP學(xué)習(xí)
JavaScript代碼美化/壓縮/格式化/加密工具:
ode/jscompressPHP學(xué)習(xí)
在線XML格式化/壓縮工具:
ode/xmlformatPHP學(xué)習(xí)
sql代碼在線格式化美化工具:
ode/sqlcodeformatPHP學(xué)習(xí)
更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《ThinkPHP常用辦法總結(jié)》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》.PHP學(xué)習(xí)
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所贊助.PHP學(xué)習(xí)
轉(zhuǎn)載請(qǐng)注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/6583.html