Table of Contents
Articles you may be interested in
Home Backend Development PHP Tutorial Summary of thinkphp development skills_PHP tutorial

Summary of thinkphp development skills_PHP tutorial

Jul 13, 2016 am 10:31 AM
thinkphp develop Skill

A summary of some skills in the development process using thinkphp. I will continue to add more when I find them in the future. More friends are welcome to leave comments below.

(1) Do not use {$_GET.id} or {$Think.get.id} directly in the template, because {$_GET.id} {$Think.get.id} does not have any Filtering, prone to XSS. It is recommended to use the I method, that is: {:I('get.id')}

(2) What should I do if I need to get the fields of a table in the database in thinkphp? An example is as follows:

$user=M('user');
$fields=$user->getDbFields();
Copy after login

The result will be returned as a one-dimensional array consisting of table fields.

(3) During the data modification process, if we only need to modify the value of a certain field, we can use the setField method instead of calling the save method every time, for example:

$user=M('user');
$user->where('id=2')->setField('username','www.phpernote.com');
Copy after login

(4) When comparison is involved, it is not necessary to use the if condition form. You can also write it in the following form:

<eq name="web" value="phpernote">value</eq> // name 变量的值等于 phpernote 就输出
<neq name="web" value="phpernote">value</neq> // name 变量的值不等于 phpernote 就输出
<gt name="age" value="5">value</gt> // name 变量的值大于 5 就输出
<egt name="age" value="5">value</egt> // name 变量的值大于等于 5 就输出
<lt name="age" value="5">value</lt> // name 变量的值小于 5 就输出
<elt name="age" value="5">value</elt> // name 变量的值小于等于 5 就输出
Copy after login

(5) In the delete operation of thinkphp, you can use delete directly to perform deletion without using where, for example:

$User->delete('2,5');//删除主键为2和5的数据
Copy after login

(6) Instructions on the usage of several quick operation functions of thinkphp.

C operation, operation (dynamic) configuration: mainly used in the Action method

Get:C('configuration parameters')

Settings: C('configuration parameters', new value)

A operation, quickly create Action objects:

$action=A('User'); Equivalent to $action=new UserAction();

D operation to quickly create model data objects:

$model=D('User'); Equivalent to $model=new UserModel();

S operation, quick operation cache method

Get: S('name')

Settings: S('name','value');

Delete: S('name',NULL);

F operation, a quick file data saving method, the usage method is the same as S operation.

(7) When naming the Model, it should be consistent with the table name in the database by default. For example, the name of the database corresponding to PhpernoteUserModel.class.php should be 'prefix_phpernote_user', and the call in the program code should be: D('PhpernoteUser');

(8) If caching is not required during the development process, the following definition can be made in the entry file:

define('NO_CACHE_RUNTIME',true);
Copy after login

(9) If you need to know some additional information during the development process, you can define it in the configuration file. Here are some common information definition methods:

'SHOW_RUN_TIME'=>true,//运行时间显示
'SHOW_ADV_TIME'=>true,//显示详细的运行时间
'SHOW_DB_TIMES'=>true,//显示数据库的操作次数
'SHOW_CACHE_TIMES'=>true,//显示缓存操作次数
'SHOW_USE_MEM'=>true,//显示内存开销
Copy after login

(10) Customize the Model class and use it when instantiating the model (the model is the database operation class), for example:

a. Create an IndexModel.class.php in the Model directory under the Lib directory in the project directory, and then write a method play in it. The content of this method is to output 1 to 10 in a loop.

b. Then in the method in Action, you can also write:

$index=M('index','IndexModel');//这里可以加上自定义的模型类一起实例化
$index->play();
Copy after login

Then 1 to 10 will be output.

(11) If you need to change the default template suffix when using thinkphp, you can define it as follows in the configuration file:

'TMPL_TEMPLATE_SUFFIX' => '.dwt'//这里就将模板后缀名改为了dwt
Copy after login

Articles you may be interested in

  • Summary of query techniques in ThinkPHP
  • Thinkphp internal function ADSLCFUI full analysis of shortcut methods
  • thinkphp prints the end A sql statement
  • The last record of the volist loop in the thinkphp template
  • Summary of commonly used system variables in Thinkphp templates
  • The simplest way to implement MVC development in PHP, model Thoughts
  • Thinkphp automatic verification and autofill invalid solutions
  • thinkphp method to turn off caching

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764116.htmlTechArticleA summary of some techniques in the development process using thinkphp. I will continue to add more if I find them in the future. More are welcome. Friends left comments below to add. (1) Do not use directly in templates...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

Four recommended AI-assisted programming tools Four recommended AI-assisted programming tools Apr 22, 2024 pm 05:34 PM

This AI-assisted programming tool has unearthed a large number of useful AI-assisted programming tools in this stage of rapid AI development. AI-assisted programming tools can improve development efficiency, improve code quality, and reduce bug rates. They are important assistants in the modern software development process. Today Dayao will share with you 4 AI-assisted programming tools (and all support C# language). I hope it will be helpful to everyone. https://github.com/YSGStudyHards/DotNetGuide1.GitHubCopilotGitHubCopilot is an AI coding assistant that helps you write code faster and with less effort, so you can focus more on problem solving and collaboration. Git

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Win11 Tips Sharing: Skip Microsoft Account Login with One Trick Mar 27, 2024 pm 02:57 PM

Win11 Tips Sharing: One trick to skip Microsoft account login Windows 11 is the latest operating system launched by Microsoft, with a new design style and many practical functions. However, for some users, having to log in to their Microsoft account every time they boot up the system can be a bit annoying. If you are one of them, you might as well try the following tips, which will allow you to skip logging in with a Microsoft account and enter the desktop interface directly. First, we need to create a local account in the system to log in instead of a Microsoft account. The advantage of doing this is

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Which AI programmer is the best? Explore the potential of Devin, Tongyi Lingma and SWE-agent Apr 07, 2024 am 09:10 AM

On March 3, 2022, less than a month after the birth of the world's first AI programmer Devin, the NLP team of Princeton University developed an open source AI programmer SWE-agent. It leverages the GPT-4 model to automatically resolve issues in GitHub repositories. SWE-agent's performance on the SWE-bench test set is similar to Devin, taking an average of 93 seconds and solving 12.29% of the problems. By interacting with a dedicated terminal, SWE-agent can open and search file contents, use automatic syntax checking, edit specific lines, and write and execute tests. (Note: The above content is a slight adjustment of the original content, but the key information in the original text is retained and does not exceed the specified word limit.) SWE-A

Learn how to develop mobile applications using Go language Learn how to develop mobile applications using Go language Mar 28, 2024 pm 10:00 PM

Go language development mobile application tutorial As the mobile application market continues to boom, more and more developers are beginning to explore how to use Go language to develop mobile applications. As a simple and efficient programming language, Go language has also shown strong potential in mobile application development. This article will introduce in detail how to use Go language to develop mobile applications, and attach specific code examples to help readers get started quickly and start developing their own mobile applications. 1. Preparation Before starting, we need to prepare the development environment and tools. head

A must-have for veterans: Tips and precautions for * and & in C language A must-have for veterans: Tips and precautions for * and & in C language Apr 04, 2024 am 08:21 AM

In C language, it represents a pointer, which stores the address of other variables; & represents the address operator, which returns the memory address of a variable. Tips for using pointers include defining pointers, dereferencing pointers, and ensuring that pointers point to valid addresses; tips for using address operators & include obtaining variable addresses, and returning the address of the first element of the array when obtaining the address of an array element. A practical example demonstrating the use of pointer and address operators to reverse a string.

See all articles