In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "what mode is thinkphp based on". In daily operation, I believe many people have doubts about what mode thinkphp is based on. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what mode is thinkphp based on?" Next, please follow the editor to study!
Thinkphp is the mvc mode. ThinkPHP is based on the MVC pattern and supports multi-tier (multi-Layer) design. It is an open source lightweight PHP framework born to simplify enterprise application development and agile WEB application development.
The operating environment of this tutorial: Windows7 system, thinkphp v5.1, Dell G3 computer.
ThinkPHP is based on the MVC pattern and supports multi-tier (multi-Layer) design.
ThinkPHP is a fast, compatible and simple lightweight domestic PHP development framework, born in early 2006, formerly known as FCS. In 2007, New Year's Day officially changed his name to ThinkPHP, released in accordance with the Apache2 open source agreement, transplanted from Struts structure and made improvements and improvements. At the same time, it also draws lessons from many excellent foreign frameworks and patterns, using object-oriented development structure and MVC pattern. It integrates the idea of Struts and TagLib (tag library), ORM mapping of RoR and ActiveRecord mode.
M (model)-Model Class
Model
The basic model class in ThinkPHP is the Think\ Model class, which completes basic CURD, ActiveRecord schemas, coherent operations, and statistical queries, and some advanced features are encapsulated in other model extensions.
Note: the design of the underlying model class is so flexible that you can even perform ORM and CURD operations on related data tables without any model definition, and the model class must be defined only when you need to encapsulate separate business logic.
Model definition
Model classes do not have to be defined, but only when there are independent business logic or attributes.
Model classes usually need to inherit the system's\ Think\ Model class or its subclasses. Here is the definition of a Home\ Model\ UserModel class:
Namespace Home\ Model; use Think\ Model; class UserModel extends Model {}
The role of the model class is to operate the database in most cases. If the model class is named according to the specification of the system, it can automatically correspond to the data table in most cases.
The model name convention corresponds to the data table (assuming the prefix definition of the data table is think_) UserModelthink_userUserTypeModelthink_user_type
V (view)-View layer
Template definition
The module files of each module are independent. In order to manage the module files more effectively, ThinkPHP divides the module files into directories. The default template file definition rules are:
View directory / [module theme /] 'controller name / operation name + template suffix
The default view directory is the module's View directory (modules can have multiple view file directories), and the frame's default view file suffix is .html.
Under each module topic, the controller name under the module is used as the directory, followed by the specific operation template file for each controller, such as:
The module file corresponding to the add operation of the User controller should be:
. / Application/Home/View/User/add.html
If the default view layer is not View, settings such as:
'DEFAULT_V_LAYER'= >' Template',// sets the default view layer name, and the corresponding template file becomes:. / Application/Home/Template/User/add.html.
The default suffix for the template file is .html, which can be configured through TMPL_TEMPLATE_SUFFIX.
'TMPL_TEMPLATE_SUFFIX'= > '.tpl'
Once defined, the template file corresponding to the add operation of the User controller becomes:. / Application/Home/View/User/add.tpl
Template theme
The template theme can make different layout and style adjustments to the same controller output.
If a module needs to support multiple sets of template files, you can use the template theme function. The template theme feature is not enabled by default. If you need to enable it, you can set the DEFAULT_THEME parameter:
/ / set the default template theme
'DEFAULT_THEME'= >' default'
After adopting the template theme, you need to create a corresponding theme directory under the view directory. Compared with the case where the template theme is not enabled, the template file is only one more layer of directory:
View/User/add.html / / before enabling template theme View/default/User/add.html / / after enabling template theme
Before the view renders the output, we can change the template theme we need to use through dynamic settings.
/ / dynamically change the template theme $this- > theme ('blue')-> display (' add') in the controller
Template assignment
If you want to output the variable in the template, you must pass the variable to the template in the controller and assign a value to the template variable through the assign method
$this- > assign ('name',$value); / / the following is the equivalent of $this- > name=$value
The assign method must be called before the display and show methods, and only the set variables are output, not the other variables (with the exception of system variables).
System variables can be output through a special label without the need to assign template variables
Once assigned, you can output variables in the template file, or if you are using a built-in template, you can output: {$name}
You can output multiple template variables in the following ways:
$array ['name'] =' thinkphp';$array ['email'] =' fdsf@123.com';$array ['phone'] =' 123456789 transactions-> assign ($array)
Template rendering
After the template is defined, you can render the template output, and the system also supports direct rendering of content output. Template assignment must be performed before the template is rendered.
Render templat
The most common way to render template output is to use the display method, which calls the format:
Display ('[template file]'[, 'character encoding'] [, 'output type']) template file can be written in the following ways:
Usage description of the template file that automatically locates the current operation without any parameters [module @] [controller:] [operation] commonly used, support cross-module template theme can be used directly with the complete template file name with the theme method (including template suffix)
Eg.
/ / automatically locate the template file of the current operation $this- > display () without any parameters
Usually the default view directory is View
If you do not define the template file according to the rules defined by the template (or if you need to call a template under another controller), use:
/ / call the edit module $this- > display ('edit') under the current controller; / / call the read module $this- > display (' Member:read') under the Member controller
If we use the template theme feature, we can also support theme calls, using:
\\ indicates that the edit module $this- > theme ('blue')-> display (' User:edit') of the User controller under the blue topic is called
Get the template address
The T function is used to generate the template file name, usage:
T ([resource: / /] [module @] [topic /] [controller /] operation, [view layering])
The return value of the T function is a complete template file name, which can be directly used for rendering output by the display and fetch methods.
Eg.
T ('Public/menu'); / / return current module / View/Public/menu.htmlT (' blue/Public/menu'); / / return current module / View/blue/Public/menu.htmlT ('Public/menu','Tpl'); / / return current module / Tpl/Public/menu.htmlT (' Admin@Public/menu'); / / return Admin/View/Public/menu.html
Using T function directly in display method
/ / use T function to output template $this- > display (T ('Admin@Public/menu'))
The T function can output different view layering modules.
Get content
If you need to get the output of the rendering template instead of the direct output, you can use the fetch method.
Eg.
$content = $this- > fetch ('Member:edit')
After you use the fetch method to get the rendered content, you can filter and replace, and so on.
Render content
If no template files are defined, or if the template contents are stored in the database, you need to use the show method to render the output.
Show method call format:
Show ('rendered content' [, 'character encoding'] [, 'output type'])
Eg.$this- > show ($content)
At this point, the study on "what model thinkphp is based on" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.