源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

thinkphp3.x自定义Action、Model及View的简单实现方法

  • 时间:2022-01-10 20:09 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:thinkphp3.x自定义Action、Model及View的简单实现方法
本文实例讲述了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页面的内容 [b]4、在操作过程中出现的错误:[/b] (1) URL中的Test的T要大写; (2) Display不需要提供文件的扩展名,默认为index [b]5、注意事项:[/b] (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 [b]9、注:Model文件名要与model的名称一直,并且在调用时区分大小写;[/b] 在xmall/conf/config.php中添加'URL_CASE_INSENSITIVE' =>true,//URL不区分大小写 [b]PS:这里推荐几款本站的格式化美化工具,相信大家在以后的开发中能够用得上:[/b] [b]php代码在线格式化美化工具: [/b][url=http://tools.jb51.net/code/phpformat]http://tools.jb51.net/code/phpformat[/url] [b]JavaScript代码美化/压缩/格式化/加密工具: [/b][url=http://tools.jb51.net/code/jscompress]http://tools.jb51.net/code/jscompress[/url] [b]在线XML格式化/压缩工具: [/b][url=http://tools.jb51.net/code/xmlformat]http://tools.jb51.net/code/xmlformat[/url] [b]sql代码在线格式化美化工具: [/b][url=http://tools.jb51.net/code/sqlcodeformat]http://tools.jb51.net/code/sqlcodeformat[/url] 更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/39.htm]ThinkPHP入门教程[/url]》、《[url=http://www.1sucai.cn/Special/129.htm]ThinkPHP常用方法总结[/url]》、《[url=http://www.1sucai.cn/Special/26.htm]smarty模板入门基础教程[/url]》及《[url=http://www.1sucai.cn/Special/350.htm]PHP模板技术总结[/url]》。 希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部