thinkphp is mvc mode. ThinkPHP is based on the MVC model and supports multi-layer (multi-Layer) design. It is an open source lightweight PHP framework born to simplify enterprise-level application development and agile WEB application development.
The operating environment of this tutorial: Windows 7 system, thinkphp v5.1 version, Dell G3 computer.
ThinkPHP is based on the MVC model and supports multi-layer (multi-Layer) design.
ThinkPHP is a fast, compatible and simple lightweight domestic PHP development framework. It was born in early 2006, formerly known as FCS. It was officially renamed ThinkPHP on New Year's Day in 2007. It is released under the Apache2 open source agreement and is derived from Struts The structure was transplanted and improved and perfected. At the same time, it also learned from many excellent foreign frameworks and patterns, using object-oriented development structure and MVC pattern, integrating the ideas of Struts and TagLib (tag library), RoR's ORM mapping and ActiveRecord. model.
M (model) – Model class
Model
in ThinkPHP The basic model class is the Think\Model class, which completes basic CURD, ActiveRecord mode, coherent operations and statistical queries. Some advanced features are encapsulated into other model extensions.
Note: The design of the basic model class is very flexible. You can even perform ORM and CURD operations on related data tables without any model definition. Only when you need to encapsulate separate business logic , the model class must be defined.
Model definition
The model class does not have to be defined. It only needs to be defined when there is independent business logic or attributes.
Model classes usually need to inherit the system\Think\Model class or its subclasses. The following is the definition of a Home\Model\UserModel class:
namespace Home\Model; use Think\Model; class UserModel extends Model{ }
Model class In most cases, it is used to operate the database. If the model class is named according to the system's specifications, it can automatically correspond to the data table in most cases.
Model name | Agree on the corresponding data table (assuming the prefix definition of the data table is think_) |
---|---|
think_user | |
think_user_type |
用法 | 描述 |
---|---|
不带任何参数 | 自动定位当前操作的模板文件 |
[模块@][控制器:][操作] | 常用写法,支持跨模块 模板主题可以和theme方法配合 |
完整的模板文件名 | 直接使用完整的模板文件名(包括模板后缀) |
eg.
//不带任何参数 自动定位当前操作的模板文件 $this->display();
通常默认的视图目录是View
如果没有按照模板定义的规则来定义模板文件(或者需要调用其他控制器下面的某个模板),使用:
//表示调用当前控制器下面的edit模块 $this->display('edit'); //表示调用Member控制器下面的read模块 $this->display('Member:read');
如果我们使用了模板主题功能,那么也可以支持主题调用,使用:
\\表示调用blue主题下面的User控制器的edit模块 $this->theme('blue')->display('User:edit');
获取模板地址
T函数用于生成模板文件名,用法: T([资源://][模块@][主题/][控制器/]操作,[视图分层])
T函数的返回值为一个完整的模板文件名,可以直接用于display和fetch方法进行渲染输出。
eg.
T('Public/menu'); //返回 当前模块/View/Public/menu.html T('blue/Public/menu'); //返回 当前模块/View/blue/Public/menu.html T('Public/menu','Tpl'); //返回 当前模块/Tpl/Public/menu.html T('Admin@Public/menu'); //返回 Admin/View/Public/menu.html
在display方法中直接使用T函数
//使用T函数输出模板 $this->display(T('Admin@Public/menu'));
T函数可以输出不同的视图分层模块。
获取内容
如果需要获取渲染模板的输出内容而不是直接输出,可以使用fetch方法。
eg. $content = $this->fetch('Member:edit');
使用fetch方法获取渲染内容后,可以进行过滤和替换等操作。
渲染内容
如果没有定义任何模板文件,或者把模板内容存储到数据库的话,就需要使用show方法来渲染输出。
show方法调用格式:
show(‘渲染内容’[,’字符编码’][,’输出类型’])
eg.$this->show($content);
【相关教程推荐:thinkphp框架】
The above is the detailed content of What is the mode of thinkphp?. For more information, please follow other related articles on the PHP Chinese website!

thinkphp是国产框架。ThinkPHP是一个快速、兼容而且简单的轻量级国产PHP开发框架,是为了简化企业级应用开发和敏捷WEB应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。

本篇文章给大家带来了关于thinkphp的相关知识,其中主要介绍了关于使用think-queue来实现普通队列和延迟队列的相关内容,think-queue是thinkphp官方提供的一个消息队列服务,下面一起来看一下,希望对大家有帮助。

thinkphp基于的mvc分别是指:1、m是model的缩写,表示模型,用于数据处理;2、v是view的缩写,表示视图,由View类和模板文件组成;3、c是controller的缩写,表示控制器,用于逻辑处理。mvc设计模式是一种编程思想,是一种将应用程序的逻辑层和表现层进行分离的方法。

本篇文章给大家带来了关于thinkphp的相关知识,其中主要介绍了使用jwt认证的问题,下面一起来看一下,希望对大家有帮助。

thinkphp扩展有:1、think-migration,是一种数据库迁移工具;2、think-orm,是一种ORM类库扩展;3、think-oracle,是一种Oracle驱动扩展;4、think-mongo,一种MongoDb扩展;5、think-soar,一种SQL语句优化扩展;6、porter,一种数据库管理工具;7、tp-jwt-auth,一个jwt身份验证扩展包。

本篇文章给大家带来了关于ThinkPHP的相关知识,其中主要整理了使用think-queue实现redis消息队列的相关问题,下面一起来看一下,希望对大家有帮助。

thinkphp查询库是否存在的方法:1、打开相应的tp文件;2、通过“ $isTable=db()->query('SHOW TABLES LIKE '."'".$data['table_name']."'");if($isTable){...}else{...}”方式验证表是否存在即可。

在thinkphp3.2中,可以利用define关闭调试模式,该标签用于变量和常量的定义,将入口文件中定义调试模式设为FALSE即可,语法为“define('APP_DEBUG', false);”;开启调试模式将参数值设置为true即可。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools