指点云用户44 发表于 2022-7-29 22:34:30

thinkphp中的模型是什么

<blockquote style="margin: 0.8em 0px; padding: 10.5px 21px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); background-color: rgb(245, 245, 245); border-left: 4px solid rgb(204, 204, 204); color: rgb(85, 85, 85); font-size: 14px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal;"><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); font-size: 16px; box-sizing: border-box; border-radius: 8px;">在thinkphp中,模型指的是企业数据和业务规则,在实际项目开发中主要实现与数据库进行操作;模型类的命名需要除去表前缀的数据库名称,采用驼峰法命名,并且首字母使用大写,模型类完成了基本的 CURD、ActiveRecord模式、连贯操作和统计查询等。</p></blockquote><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">本文操作环境:Windows10系统、ThinkPHP5版、Dell G3电脑。</p><h2 style="margin: 0px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">thinkphp中的模型是什么</h2><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">模型(Model)是 ThinkPHP 中一个很重要的概念,与之有关的还包括模型的定义与实例化。</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">MVC 是一种将应用程序的逻辑层和表现层进行分离的方法,ThinkPHP 也是基于MVC设计模式的。ThinkPHP 中模型(M)的定义是由 Model 类来完成的。</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">ThinkPHP 中基础的模型类就是 Model 类,该类完成了基本的 CURD、ActiveRecord 模式、连贯操作和统计查询等。</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px;">1、什么是模型(Model)</strong></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">模型表示企业数据和业务规则,实际项目开发中,主要实现与数据库进行操作。</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"><strong style="margin: 0px; padding: 0px;">2、模型的定义规则</strong></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">模型类的命名规则是除去表前缀的数据表名称,采用驼峰法命名,并且首字母大写,然后加上模型类的关键词Model,再加上类文件后缀.class.php</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">案例:实现移动办公自动化系统的组织结构功能</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">1.设计数据库db_think</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">2.设计数据表结构(tk_dept)</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">3. 使用SQL语句创建数据表</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">4.创建一个Dept控制器</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">5.导入add.html模板到./Application/Admin/View/Dept文件夹下</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">6.更改add.html页面中的images/css/js路径信息</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">7.更改办公系统左侧导航链接,要用到的知识点:</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">U方法</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">主要功能:用于生成导航链接,如/index.php/Admin/Dept/add,使用方法如下</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);">在实际项目开发中我们通常使用第三种方式,U(模块/控制器/操作方法)</p><p style="margin-top: 15px; margin-bottom: 15px; padding: 0px 0px 0px 10px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); color: rgb(61, 70, 77); box-sizing: border-box; border-radius: 8px; font-family: Helvetica Neue, Helvetica, PingFang SC, 微软雅黑, Tahoma, Arial, sans-serif; white-space: normal; background-color: rgb(255, 255, 255);"></p><p><br/></p><link rel="stylesheet" href="//www.zhidianyun.cn/source/plugin/wcn_editor/public/wcn_editor_fit.css?v134_TZ8" id="wcn_editor_css"/>
页: [1]
查看完整版本: thinkphp中的模型是什么