thinkphp3.x自定義Action、Model及View的簡單實(shí)現(xiàn)方法
來源:易賢網(wǎng) 閱讀:912 次 日期:2016-08-20 13:58:58
溫馨提示:易賢網(wǎng)小編為您整理了“thinkphp3.x自定義Action、Model及View的簡單實(shí)現(xiàn)方法”,方便廣大網(wǎng)友查閱!

本文實(shí)例講述了thinkphp3.x自定義Action、Model及View的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

1、在xmall/Lib/Action中創(chuàng)建文件TestAction.class.php

class TestAction extends Action{

   function index(){

    $this->display("test");

   }

}

2、在xmall/tpl下創(chuàng)建default文件夾,在default下創(chuàng)建Test文件夾,在Test下創(chuàng)建test.html模版文件;

3、執(zhí)行URL:http://localhost/xmall/index.php/Test/index就會出現(xiàn)test.html頁面的內(nèi)容

4、在操作過程中出現(xiàn)的錯(cuò)誤:

(1) URL中的Test的T要大寫;

(2) Display不需要提供文件的擴(kuò)展名,默認(rèn)為index

5、注意事項(xiàng):

(1) 為方便調(diào)試,應(yīng)在index.php入口文件中添加

define("APP_DEBUG",true);

(2) 最好在配置文件(xmall/Conf/config.php)中指定默認(rèn)模版:'DEFAULT_THEME' => 'default'

6、在xmall/lib/Model下創(chuàng)建文件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、執(zhí)行URL:http://localhost/xmall/index.php/Index/test,頁面輸出123456

9、注:Model文件名要與model的名稱一直,并且在調(diào)用時(shí)區(qū)分大小寫;

在xmall/conf/config.php中添加'URL_CASE_INSENSITIVE' =>true,//URL不區(qū)分大小寫

希望本文所述對大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

更多信息請查看網(wǎng)絡(luò)編程
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
云南網(wǎng)警備案專用圖標(biāo)
聯(lián)系電話:0871-65317125(9:00—18:00) 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專用圖標(biāo)