thinkphp3.x自定义Action、Model及View的简单实现方法
作者:yanhui_wei 时间:2024-05-11 10:04:01
本文实例讲述了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不区分大小写
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
标签:thinkphp,Action,Model,View
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
golang定时器Timer的用法和实现原理解析
2024-02-17 04:23:08
Python Ruby 等语言弃用自增运算符原因剖析
2022-10-11 07:42:31
![](https://img.aspxhome.com/file/2023/6/131746_0s.png)
Golang拾遗之实现一个不可复制类型详解
2024-05-13 10:40:29
python实现键盘输入的实操方法
2022-07-25 19:18:25
![](https://img.aspxhome.com/file/2023/5/121485_0s.jpg)
Python 启动时选择32位 或64位版的操作
2021-04-29 23:50:43
![](https://img.aspxhome.com/file/2023/8/125048_0s.jpg)
mysql alter table 修改表命令详细介绍
2024-01-13 21:35:38
chatGPT使用及注册过程中常见的一些错误解决方法(所有报错汇总)
2023-03-02 22:27:23
![](https://img.aspxhome.com/file/2023/6/132416_0s.png)
windows下MySQL5.6版本安装及配置过程附有截图和详细说明
2024-01-13 18:58:56
![](https://img.aspxhome.com/file/2023/5/65285_0s.png)
mysql8.0.19忘记密码处理方法详解
2024-01-16 10:42:22
ASP提高数据显示效率-缓存探幽
2007-09-28 12:37:00
go mod详细使用教程
2024-04-26 17:32:19
![](https://img.aspxhome.com/file/2023/8/133988_0s.jpg)
如何用Python制作微信好友个性签名词云图
2023-02-24 07:46:20
![](https://img.aspxhome.com/file/2023/7/123567_0s.jpg)
python 基于Appium控制多设备并行执行
2022-12-11 12:00:06
python中join与os.path.join()函数实例详解
2023-08-23 19:20:51
![](https://img.aspxhome.com/file/2023/6/62866_0s.png)
关于网站地图
2011-01-06 12:14:00
![](https://img.aspxhome.com/file/UploadPic/20111/6/116-64s.jpg)
日常收集整理php正则表达式(超常用)
2024-05-03 15:35:49
如何快速定位页面中复杂 CSS BUG 问题
2009-01-15 12:23:00
远程访问MySQL数据库的方法小结
2024-01-13 17:58:57
Fibonacci数,Θ(log n)
2010-03-28 13:28:00
50个常用sql语句 网上流行的学生选课表的例子
2024-01-24 10:12:23