拉拉后花园,有一种冷叫忘穿秋裤,浒
本文实例讲述了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不区分大小写
ps:这里推荐几款本站的格式化美化工具,相信大家在以后的开发中能够用得上:
php代码在线格式化美化工具:
javascript代码美化/压缩/格式化/加密工具:
在线xml格式化/压缩工具:
sql代码在线格式化美化工具:
更多关于thinkphp相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》、《thinkphp常用方法总结》、《smarty模板入门基础教程》及《php模板技术总结》。
希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
PHP date_default_timezone_set()设置时区操作实例分析
网友评论