search
HomeBackend DevelopmentPHP TutorialThinkphp study notes, thinkphp study notes_PHP tutorial

Thinkphp study notes, thinkphp study notes

Front and backend configuration:

Create a Conf folder

in the root folder Create a

config.php file under the Conf folder, which stores public configuration information for easy front-end and back-end calls.

Simple definition of 404Page

Pseudo-static removal.html

ConfigURL_HTML_SUFFIX => ‘’

Assign template

1:$this ->assign(‘XXX’,$XXX);

2:$this->a = 111;

3:$this->assign(‘xxx’,$xxx)->display();

Time stamp processing

{$v.time|date='y-m-d H:i',###}

Group:

After grouping common the file name used individually should be function.php instead of common. php

JS External address cannot be resolved UFunction :

HtmlPage:

Non-application group writing method:

How to write application groups

The last empty space is used to process pseudo-static .html Remove .html

JsPage:

Error page customization:

Conf folder

Data storage:

1)

2):

Data reading:

1):

2):

Random number:

mt_rand(min,max);

U method to remove .htmlend

Verification code production:

SESSION stored in database :

1): In configuration file

2):Create database table:

ThinkPHPCommonly used various methods

A() LoadActionClass
D() LoadModel Class
S() Global cache configuration
L() Get language definition
C() Get configuration value
F() Fast file data reading and saving For simple type data string, array
U() is used to complete the pair URLAssembly of addresses
I() Quickly create an object instance

1.A Quickly CreateActionObject

$action=new UserAction();// is equivalent to the following writing :$action=A("User");And, if the current UserAction class has not been introduced yet, the A method will be introduced automatically. And with the support of singleton mode, the same Action object will not be created repeatedly.

The

A method supports cross-project calls, for example:

$action=A("User",'Admin'); //InstantiationAdmin project’s UserAction class

2.D Quickly create model data objects

First define the model class, such as UserModel, then you can use D() function operates on data. For example:

First create a file named "your project "/Lib/Model >UserModel.class.php’s PHP script, the content is as follows:
class UserModel extends Model{}

Then, without adding any attributes and methods, you can perform the following operations:


$User=D("User"); //
InstantiateUserObject, User is an object you created in the database named "prefix _user" The data table of can also be replaced by $User=new UserModel() to instantiate the object. After instantiation, you can perform a series of operations such as adding, deleting, checking, and modifying the data, such as:
$User->find(1); //
The search primary key is 1’s record

When we are doing user gold coins or points or voting, we need to add

1 to the specified field. At this time, I can write like this

$User->score='(score 1)';$s->save();

This will save us a lot of steps.

If you want to modify a specified field, it can be abbreviated as follows:

D('User')->setField('name','hehe','id=2');

The main difference between the

D

method and the M method is: The

M

method does not need to create a model class file. The M method does not read the model class, so automatic verification is invalid by default, but it can be dynamically It is implemented by assignment; and the D method must create a model class. We can use the following two methods to create a mapping object of a data table.

First type:

$Test=D('Test');

Second type:

$Test=new Model('Test');

Although both of these can perform

select, insert, delete, udpate operations on data, there is a big difference in data verification. Using the first method to instantiate a model will There is a data checking function. For example, you can define that if title is not filled in, it will prompt Please enter the title ” (This is an automatic verification function provided by tp. Of course, it also needs to be in the corresponding model Define the verification conditions ); The

D

method can automatically detect the model class, and it will throw an exception if it does not exist. At the same time, the instantiated model will not be repeatedly instantiated (single case). The default D method can only support calling the current project ( or application )Model below. For example:

$user=new UserModel();

Equivalent to

$user=D('user');

If an empty model is instantiated, for example:

$Demo=new Model();

Then it is equivalent to:

$Demo=M();


3.S
Quick operation caching method
ThinkPHP
Abstract various caching methods into a unified cache class to call, and ThinkPHP unifies all caching mechanisms into one S method to operate, so different caches are used There is no need to pay attention to specific caching details when using this method. Such as:

S('data',$Data); //Use data to identify cache$Datadata
S('data',$Data,3600); //Cache$DataData3600Seconds
$Data=S('data'); //Get cached data
S('name',null); // Delete cache identifiername

4.L Quickly operate language variables

The

L method provides multi-language support and can quickly set and obtain language definitions.

L('USER_INFO','User information '); //Set the language named USER_INFO Variable
L('USER_INFO'); //Get the language variable value of USER_INFO
//Batch assignment
$array['USER_INFO']='User information';$array['ERROR_INFO']='Error message';
L($array);

5.C To quickly operate configuration variables, the usage is C("Fill in the subscript of the array in the configuration file here ")

C('USER_AUTH_ON',true); //Set the configuration parameter named USER_AUTH_ON
C('USER_AUTH_ON'); / /Get the variable value of USER_AUTH_ON

Same as L, C also supports batch assignment

Note: Configuration parameters are not case-sensitive

In addition, starting from the 1.5 version, the C method also supports the operation of two-dimensional arrays, for example:

C('USER.USER_TYPE',1);
C('USER.USER_AUTH_ON');

6. F File data saving method

The

F method is mainly used for writing, changing and deleting project file data. Its working mechanism is similar to the S method. The difference lies in its different uses. The directory where the data is saved is also different, and the caching method cannot be specified because the data is saved in file form by default. The F method uses the var_export method, so it can only support simple data types and does not support object caching.

7. U is used to complete the assembly of URL addresses. The feature is that it can automatically be based on the current URL Modes and settings generate corresponding URLaddress

The format of this function is: U('Address','Parameters','Pseudo-static','Whether to jump','Display domain name');The advantage of using the U method instead of hard-coding the URL address is that once your environment changes Or parameter settings change, you don't need to change any code in the template. The calling format in the template needs to be {:U('address', 'parameter'… )} way.

Usage example of

U method:

U('User/add') // Generate the User module’s add operation address

Can also support group calls:

U('Home/User/add') // Generate Home grouped User moduleaddoperation address

Of course, you can also just write the operation name to indicate calling the current module

U('add') // Generate the add operation address of the current access module

In addition to group, module and operation names, we can also pass in some parameters:

U('Blog/read?id=1') // Generate Blog module's read operation And id is 1’s URLaddress

The second parameter of the

U method supports incoming parameters and supports two definition methods: array and string. If only string parameters can be defined in the first parameter, the following methods are Equivalent:

U('Blog/cate',array('cate_id'=>1,'status'=>1))
U('Blog/cate','cate_id=1&status=1')
U('Blog/cate?cate_id=1&status=1')

Import CSS/JS File

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1077130.htmlTechArticleThinkphp study notes, thinkphp study notes front and backend configuration: Create a Conf folder Conf file in the root directory folder Create a config.php file under the folder to store the public...
Statement
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
thinkphp是不是国产框架thinkphp是不是国产框架Sep 26, 2022 pm 05:11 PM

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

一起聊聊thinkphp6使用think-queue实现普通队列和延迟队列一起聊聊thinkphp6使用think-queue实现普通队列和延迟队列Apr 20, 2022 pm 01:07 PM

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

thinkphp的mvc分别指什么thinkphp的mvc分别指什么Jun 21, 2022 am 11:11 AM

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

实例详解thinkphp6使用jwt认证实例详解thinkphp6使用jwt认证Jun 24, 2022 pm 12:57 PM

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

thinkphp扩展插件有哪些thinkphp扩展插件有哪些Jun 13, 2022 pm 05:45 PM

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使用think-queue实现redis消息队列Jun 28, 2022 pm 03:33 PM

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

thinkphp 怎么查询库是否存在thinkphp 怎么查询库是否存在Dec 05, 2022 am 09:40 AM

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

thinkphp3.2怎么关闭调试模式thinkphp3.2怎么关闭调试模式Apr 25, 2022 am 10:13 AM

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

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),