您好,欢迎访问一九零五行业门户网

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

这篇文章主要介绍了thinkphp3.x自定义action、model及view的简单实现方法,结合实例形式详细分析了thinkphp3.x自定义模型、视图及控制器的具体步骤与相关实现技巧,需要的朋友可以参考下
本文实例讲述了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不区分大小写
以上就是thinkphp3.x自定义action、model及view的简单实现方法的详细内容。
其它类似信息

推荐信息