PHP Framework thinkphp Framework Entry knowledge

Source: Internet
Author: User
Tags constant extend join php file php code php framework prepare port number

Thinkphp is a free open source, fast, simple object-oriented lightweight PHP development Framework, founded in early 2006, followed the release of Apache2 Open source protocol for Agile Web application development and simplified enterprise application development. Thinkphp has been adhering to the concise and practical design principles since its inception, while maintaining excellent performance and simplicity of the code, but also focus on ease of use. and has many original functions and features, with the active participation of community teams, continuous optimization and improvement in ease of use, scalability and performance has grown into the most leading and influential Web application development framework in the country, with a number of typical cases ensuring that it can be used consistently for business and portal-level development.

thinkphp PHP framework based on MVC
M–model Model work: Responsible for the operation of the data
V–view view (template) Work: Responsible for front page display
C–controller Controller (module) Work: Description function

Thinkphp Core Document Introduction
├─thinkphp.php Frame Entry File
├─common Framework Public Files
├─conf Framework Configuration file
├─extend Framework Extended Directory
├─lang Core Language Pack Directory
├─lib Core Class Library Directory
│├─behavior Core Behavior Class Library
│├─core Core base Class Library
│├─driver Built-in Drive
││├─cache Built-in Cache driver
││├─DB Built-in Database driver
││├─taglib built-in Tag Driver
││└─template Built-in template engine driver
│└─template Built-in template engine
└─TPL System Template Directory

#项目目录结构及说明:
Home Foreground Application Folder
├─common Project common file directory
├─conf Project configuration Directory
├─lang Project Language Directory
├─lib Project Class Library Directory
│├─action Action Class Library Directory
│├─behavior Behavior Class Library Directory
│├─model Model Class Library Directory
│└─widget Widget Class Library Directory
├─runtime Project Runtime Directory
│├─cache Template Cache Directory
│├─data Data Cache Directory
│├─logs Log file directory
│└─temp Temporary Cache Directory
└─TPL Project Template Directory

thinkphp 3 MVC pattern and URL access
What is MVC
M-model write the Model class to manipulate the data
V-view Write HTML file, page rendering
C-controller Write class file (UserAction.class.php)
The MVC features of thinkphp
Writing is very flexible, only view can be executed

Thinkphp's MVC-corresponding directory
M project directory/application directory/lib/model
V project directory/application directory/TPL
C project directory/application directory/lib/action
URL Access C
4 Ways to access URLs
1.PATHINFO mode

http://domain name/project name/Entry file/Module name/method name/Key 1/value 1/Key 2/value 2

2. General mode

http://domain name/project name/entry file? m= Module name &a= method name & key 1= value 1& key 2= value 2

3.REWRITE mode

http://domain name/project name/Module name/method name/Key 1/value 1/Key 2/value 2

4. Compatibility mode

http://domain name/project name/entry file? S= Module Name/method name/Key 1/value 1/Key 2/value 2

thinkphp 3.1.2 Output and model use
Output of thinkphp 3
A, through the Echo and other PHP native output mode in the page output
b, through the Display method output
To assign a variable, you can use the Assign method
C, modify the left and right delimiters
Hugh to modify configuration items in the configuration file
' Tmpl_l_delim ' => ' <{',//modify left delimiter
' Tmpl_r_delim ' => '}> ',//Modify right delimiter

The model of thinkphp 3 uses
You need to manipulate the database in a method using the form new Model (table name)
$m =new Model (' User ');
$arr = $m->select ();
' Db_type ' => ' mysql ',//Set Database type
' Db_host ' => ' localhost ',/set host
' Db_name ' => ' thinkphp ',/Set database name
' Db_user ' => ' root ',//Set username
' Db_pwd ' => ',//Set Password
' Db_port ' => ' 3306′,//Set port number
' Db_prefix ' => ' tp_ ',//Set table prefix
You can also configure using the DSN method
' Db_dsn ' => ' mysql://root: @localhost: 3306/thinkphp ',//Configure database information using DSN
If both approaches are present, the DSN method takes precedence

There is also a simple and practical way to model
M () is equivalent to new Model ();
$m =m (' User ');
$arr = $m->select ();

Use the example of the model to be able to manipulate the data, the work of the operation is to the database to carry on the enhancement to check curd
Add-C Create $m->add ()
Delete-D delete $m->delete ()
Change-u Update $m->save ()
Check-R Read $m->select ()

A, templates can traverse arrays


1
2
3
<volist name= ' data ' id= ' VO ' >
<{$vo .id}>----<{$vo .username}>-----<{$vo .sex}><br/>
</volist>
b, we can open the debugging function of the Page_trace
1. Turn on the debugging function
3. Open Debug mode (index.php in main portal file configuration)
Define (' App_debug ', true);
2. We need to set up the configuration file to open the page trace
' Show_page_trace ' =>true,//open page TRACE, need to have $this->display () to show

Curd attribute
reads the data
reads read
$m =new Model (' user ');
$m =m (' user ');
Select
$m->select ()//Get all data , returns
Find
$m->find (2) as an array,//Gets a single data
GetField (field name)//Gets a specific field value
$arr = $m->where (' id=2′)-> GetField (' username ');
Create Data
Add create
$m =new Model (' user ') to data,
$m =m (' user '),
$m-> Field name = value
$m->add ();
The return value is the new ID number
Delete data
$m =m (' User ');
$m->delete (2);               //delete data with ID 2
$m->where (' id=2′)->delete (), same as above, delete data with ID 2
The return value is the number of affected rows
Update data
$m =m (' User ');
$data [' id ']=1
$data [' username ']= ' ztz2′;
$m->save ($data);
The return value is the number of affected rows

Query method
Normal Query method
A, string
$arr = $m->where ("Sex=0 and Username= ' Gege ')->find ();
B, Array
$data [' sex '] = 0;
$data [' username ']= ' gege ';
$arr = $m->where ($data)->find ();
Note: This is by default the relationship between and, if you use an OR, you need to add an array value
$data [' Sex ']=0;
$data [' username ']= ' gege ';
$data [' _logic ']= ' or ';
Expression Query method
$data [' id ']=array (' lt ', 6];
$arr = $m->where ($data)->select ();
EQ equals
Neq is not equal to
the GT is greater than
Egt is greater than or equal to
LT is less than
ELT is less than or equal to
like fuzzy query
$data [' username ']=array (' like ', '%ge ');
$arr = $m->where ($data)->select ();
Notlike
$data [' username ']=array (' notlike ', '%ge% '); There are no spaces in the middle of//notlike
$arr = $m->where ($data)-> Select ();

Note: If a field is to match multiple wildcard characters
$data [' username ']=array (' like ', Array ('%ge% ', '%2% ', '% Five '), ' and ');/If there is no third value, the default relationship is an or relationship
$arr = $m->where ($data)->select ();
BETWEEN
$data [' id ']=array (' between ', Array (5,7));
$arr = $m->where ($data)->select ();
SELECT * from Tp_user WHERE ((ID BETWEEN 5 and 7))
$data [' id ']=array (' Not between ', Array (5,7));/Note that there must be a space between not and between
$arr = $m->where ($data)->select ();
In
$data [' id ']=array (' in ', Array (4,6,7));
$arr = $m->where ($data)->select ();
SELECT * from Tp_user WHERE (ID in (4,6,7))

$data [' id ']=array (' Not in ', Array (4,6,7));
$arr = $m->where ($data)->select ();
SELECT * from Tp_user WHERE (ID isn't in (4,6,7))
Interval query
$data [' ID ']=array (Array (' GT ', 4), array (' LT ', 10)];/The default relationship is the relationship of and
SELECT * from Tp_user WHERE ((ID > 4) and (ID < 10))

$data [' ID ']=array (Array (' GT ', 4), array (' LT ', ten), ' or ')//relationship is the relationship between or

$data [' Name ']=array (' like ', '%2% '], array (' like ', '% Five '), ' gege ', ' or ');
Statistics Query
Count//Get number
max  //Get maximum
min  //Get minimum
avg  //Get average
sum& nbsp; //Get sum
SQL Direct Query
A, query Main number processing
result set of successfully returned data
failed to read data return Boolean false
$m =m ();
$result = $m-& Gt;query ("Select *  from T_user where ID >50″);"
Var_dump ($result);
B, execute for update write
successfully returns the effect of rows
Failure returns boolean false
$m =m ();
$result = $m->execute ("INSERT INTO T_user" ( username) VALUES (' ztz3′) ');
Var_dump ($result);

Coherent operation
Common consistent operation
1.where
Help us set query criteria
2.order
Sort the results
$arr = $m->order (' id desc ')->select ();
$arr = $m->order (array (' ID ' => ' desc ', ' Sex ' => ' ASC '))->select ();
3.limit
Limit results
Limit (2,5)
Limit (' 2,5′)
Limit (//limit) (0,10)
4.field
Set query fields
Field (' username as Name,id ')
Field (Array (' username ' => ' name ', ' ID ')
Field (' id ', true)//Get all fields except ID
5.table
Set table name
6.group
Group
7.having

Alias is used to define an alias string for the current data table
Page is used to query pagination (internally converts to limit) strings and numbers
Join* used to support strings and arrays for a join to a query
Union* used to support strings, arrays, and objects for the Union of Queries
Distinct distinct support Boolean values for queries
Lock mechanism Boolean value for database lock
Cache is used for query caching to support multiple parameters (later described in detail in the cache section)
Relation for associative queries (requires associated model extension support) string
Validate for data auto-validation arrays
Auto for Data Auto Complete array
Filter for data filter strings
Scope* used to name range strings, arrays

View
Use of templates
A, rules
Folders under the Template folder [tpl]/[Group folder/][template theme Folder/] and module name [index]/and a file with the same name as the method name [Index].html (. TPL)
Replace the suffix name of the template file (modify configuration file)
' Tmpl_template_suffix ' => '. html ',//change template file suffix name
b, modify the template file directory hierarchy
' Tmpl_file_depr ' => ' _ ',//Modify template file directory hierarchy
C, template theme
' Default_theme ' => ' your ',//set Default template theme
You need to create a new your folder under TPL as a template theme folder
How do I dynamically modify a template theme?
1, in the background to prepare a function, modify the default template items in the config.php file
2, through the URL to pass t= theme parameters can modify different templates
' Default_theme ' => ' your ',//set Default template theme
' Tmpl_detect_theme ' =>true,//automatically detects template themes
' Theme_list ' => ' your,my ',//Supported template Topics list

Output template Content
A, display
No parameters in 1.display
$this->display ();
2. can be with parameters
$this->display (other template files under this module folder);
$this->display (' index2′);

$this->display (template files in other folders);
$this->display (' public:error '); Note that only the public folder and the error.html in the TPL are required, and there is no public module required

$this->display (template files under folders under other topics);/need to open topic support
$this->display (' My:Index:index ');

$this->display (a URL path);
$this->display ('./public/error.html ');

$this->display ('/public/error.html ', ' utf-8′, ' text/xml ');

$this->show ($content);
3.fetch method
Get the contents of the template file and return it as a string
$content = $this->fetch (' Public:error ');
4.show method
Template files are not required and can be exported directly to the template content
$content = $this->fetch (' Public:error ');
Dump ($content);
$content =str_replace (' h1′, ' I ', $content);
$this->show ($content);
Assignment in a template
$this->assign (' name ', ' Zhao Tun ');
$this->name= ' Zhao Tun is 2′;
$this->display ();
Template replacement
__PUBLIC__: The public directory that will be replaced with the current Web site is usually/public/
__ROOT__: Replace the address of the current Web site (excluding the domain name)
__APP__: Replaces the URL address of the current item (excluding the domain name)
__GROUP__: Replaces the URL address of the current group (excluding the domain name)
__URL__: Replace the URL address of the current module (excluding the domain name)
__ACTION__: Replaces the URL address of the current operation (excluding the domain name)
__SELF__: Replaces the current page URL

Replace the template variable rule, modify the configuration item
' Tmpl_parse_string ' =>array (///Add your own template variable rules
' __css__ ' =>__root__. ' /public/css ',
' __js__ ' =>__root__. ' /public/js ',
),

Variables in the template
Variable output
1. Scalar output
2. Array output
{$name [1]}//index array
{$name [' K2 ']}//associative array
{$name. K1}
3. Object output
{$name: k}
{$name->k}
System variables
{$Think. Get.id}
Working with functions
{$name |strtoupper} generates a compiled file that is <?php Echo (Strtoupper ($name));?>
{$name |date= ' Y m D h:i:s ', ###}
Default value
{$name |default= ' here is the default value '}
Operator
+–*/% ++-
{$name + +}

Basic syntax in a template
Import CSS and JS files
1, CSS Link
JS SCR
<link rel= ' stylesheet ' type= ' text/css ' href= ' __public__/css/test.css '
<script src= ' __public__/js/test.js ' ></script>
2.import
<import type= ' js ' file= ' js.test '/>//Import the Test.js file in the JS directory below the public folder, the import tag can omit the type attribute, and the default is JS
<import type= ' css ' file= ' css.test '/>
You can change the default folder settings BasePath properties
<import type= ' js ' file= ' js.my ' basepath= './other '/>
3.load
method to automatically detect an imported file type
<load href= ' __public__/js/test.js '/>
Branch structure
1, if
<if condition= ' $sex eq ' man ' >
Men are made of mud.
<else/>
Women are made of water.
</if>

<if condition= ' $age lt 18′>
Minor
<elseif condition= ' $age eq '/>
Age
<else/>
Adult
</if>
> GT
< LT
= = EQ
<= ELT
>= EGT
!= NEQ
= = = Heq
!== Nheq

<switch name= ' number ' >
<case value= ' 1′> a monk fetching water to eat </case>
<case value= ' 2′> two a monk table water to eat </case>
<case value= ' 3′> three monks have no water to eat </case>
<default/> This is the default value
</switch>
Loop structure
1.for
<table border= ' 1′width= ' 500′>
<for start= ' end= ' name= ' j ' step= ' -2′comparison= ' GT ' >
<tr><td>{$j}</td><td>abc</td></tr>
</for>
</table>

2.volist
<volist name= ' list ' id= ' V ' >
{$v .username}<br/>
</volist>
3.foreach
<foreach name= ' list ' item= ' V ' key= ' K ' >
{$k} ——-{$v}<br/>
</foreach>
Special label
1. Comparison label
eq or Equal equals
NEQ or notequal is not equal to
GT Greater than
EGT is greater than or equal to
LT is less than
ELT is less than or equal to
HEQ constant equals
Nheq not constant equals

2. Range Label
In
<in name= ' n ' value= ' 9,10,11,12′> in these numbers <else/> not within the range of these numbers </in>
<notin name= ' n ' value= ' 9,10,11,12′> in these numbers <else/> not within the range of these numbers </in>
Between
<notbetween name= ' n ' value= ' 1,10′>{$n} between 1-10 <else/>{$n} is not between 1 and 10 </between>
3.present
Label to determine if the template variable has been assigned,
<present name= ' m ' >m is assigned a value <else/>m not assigned </present>
4.Empty
The empty label determines whether the template variable is empty,
<empty name= ' n ' >n for null assignment <else/>n value </empty>
5.Defined
To determine whether a constant has been defined
6.Define
Defining constants in a template
7.Assing
Variable assignment in a template

Other labels used
1. Use PHP code directly in the template
<php> echo "I am Zhao Tun" </php>
2. Suggest changing the left and right delimiters
Change in configuration file
' Tmpl_l_delim ' => ' <{',//modify left delimiter
' Tmpl_r_delim ' => '}> ',//Modify right delimiter

The

Template usage
Template contains the
<include file= full template file name/>
<include file= "./tpl/default/public/header.html"/
<include file= "read"/>
<include file= "Public:header"/>
<include file= "Blue:User:read" "/>
<include file=" $tplName "/>
<include file=" header "title=" thinkphp framework "keywords=" open source Web development framework "/
The variables in the template are accepted by [variable]
<include file= ' file1,file2′/>
Template Rendering
1, automatically open template render settings profile
' layout_on ' => true,//Open Template Rendering
Prepare a template rendering page, use {__content__} in the page to accept the contents of the specific template page
If you do not want to use the render template in a specific template, you can add {__nocontent__}
2 at the top of the page , do not turn on automatic template rendering you can add
<layout name= ' layout '/> to the top of each page of the page,
3. Using Tips
You can also use the contents of other template files in the render template file
<include File= ' Public:header '/>
<body>
<p> This is the rendering page!!! </p>
{__content__}
</body>
Template inheritance    

module and operation of the controller
Empty modules and empty operations
1. Null operation
function _empty ($name) {
$this->show ("$name does not exist <a href= ' __app__/index/index ' > Return home </a>");
}
2. Empty module
Class Emptyaction extends action{
function index () {
$city =m (' City ');
$arr = $city->select ();
$this->assign (' list ', $arr);
$name =module_name;
$this->display ("City: $name");
}
}

Predecessors and post operations
1, predecessor operation: _before_ operation name
2. Post operation: _after_ operation name

Url
URL Rules
1, the default is case-sensitive
2, if we do not want to distinguish between case can change the configuration file
' Url_case_insensitive ' =>true,//url case-insensitive
3. If the module is named Usergroupaction
Then the URL to find the module is necessary to write

Http://localhost/thinkphp4/index.php/user_group/index

4. If ' url_case_insensitive ' =>false
Then the URL can also be written as

Http://localhost/thinkphp4/index.php/UserGroup/index

URL pseudo static


' Url_html_suffix ' =&gt; ' html|shtml|xml ',//limit pseudo-static suffixes


URL Routing


1. Start routing


To turn on routing support in the configuration file


2. Using routing


1. Regular expression Configuration routing


' My ' =&gt; ' index/index ',//static address routing


': Id/:num ' =&gt; ' index/index ',//dynamic address Routing


' year/:year/:month/:d ate ' =&gt; ' index/index ',//dynamic and static mixed address routing


' year/:yeard/:monthd/:d ated ' =&gt; ' index/index ',//dynamic and static mixed address routing


Plus d means the type can only be a number


' my/:id$ ' =&gt; ' Index/index ', plus $ to indicate that the address can only be my/1000 behind can not have other content


2. Regular expression Configuration routing


'/^year/(D{4})/(D{2})/(d{2})/' =&gt; ' index/index?year=:1&amp;month=:2&amp;date=:3′


3, Attention matters:


1. The more complex the route to the front


' Url_route_rules ' =&gt;array (


' my/:year/:month:/:d ay ' =&gt; ' index/day ',


' My/:idd ' =&gt; ' Index/index ',


' My/:name ' =&gt; ' Index/index ',


)


2. You can use $ as an exact match for routing rules


' Url_route_rules ' =&gt;array (


' my/:idd$ ' =&gt; ' Index/index ',


' my/:name$ ' =&gt; ' Index/index ',


' my/:year/:month:/:d ay$ ' =&gt; ' index/day ',


),


3. Using a regular matching method


' Url_route_rules ' =&gt;array (


'/^my/(d+) $/' =&gt; ' index/index?id=:1′,


'/^my/(w+) $/' =&gt; ' index/index?name=:1′,


'/^my/(D{4})/(D{2})/(d{2}) $/' =&gt; ' index/day?year=:1&amp;month=:2&amp;day=:3′,


),

URL Rewrite
URL generation

Grouping, page jumps and Ajax
Multi-application Configuration Tips
Working with Groups
Page Jump
$this->success (' query success ', U (' user/test '));
$this->redirect (' User/test ', ", 5, ' page is jumping ');
Ajax Tips
The big C method gets the array name and value in the configuration file
echo C (' Db_user ');

Large F Method File processing
Write: F (' filename ', ' array ', ' directory ');
READ: F (' filename ', ', ', ' directory ');

Large U method URL handling
in PHP
U (' Method name ')
In the template
Current function {: U (' Method name ')}
Other functions {: U (' function/Method name ')}

* File Introduction
<css file= ' __public__/css/base.css '/>
<js file= ' __public__/js/base.js '/>

* Form Processing
Method 1 $this->_post (");
Get submit form, use function htmlspecialchars () filter
$username = $this->_post (' username ');

Method 2 I (' username '); [3.1.3 New features]
Large I, automatically judge Post and get
$username =i (' username ');
echo I (' username ', ' default value when there is no value ', ' use function ');

To see if there are any data submissions:
Print_r (I (' post. '));

Prevent access to form processing functions to enhance security
Method 1
if (! $this->ispost ()) _404 (' page does not exist ', U (' index '));
Echo ' normal submission ';

Method 2 (Recommended) halt page to customize the error page:
if (!is_post) Halt (' page does not exist ');
Echo ' normal submission ';

Development method: Add in conf/config.php: ' Tmpl_exception_file ' => './public/tpl/error.html ',
File Accept error content:./public/tpl/error.html, can only write native PHP, support constants, such as __app__
<?php echo $e [' message '];?>

Returns the inserted ID value, starting with the database from 1
if (M (' user ')->data ($data)->add ()) {
$this->success (' Add success ', ' Index ');
}else{
$this->error (' Add failed ');
}

* Output to Template

1, data preparation
Method 1
$this->assign (' variable name ', ' variable value ')

Method 2
$this-> Variable name = ' variable value ';

Method 3 (new version, shortened code)
$this->assign (' variable name ', ' variable value ')->display ();

Method 4 (one row)
$this->assign (' Data ', M (' User ')->select ())->display ();

2, template output
Method 1 (. Syntax determines whether an object or array, configuration parameter:tmp_var_identify=> ' array ', which is considered an array to increase speed)
<foreach name= ' data ' item= ' V ' >
{$v. username}-{$v. password}-{$v. time|date= ' y-m-d h:i:s,### '}
</foreach>

Use function {:p hpinfo ()}

Method 2
Volist

* Group Application (application group) before and after the table with only one entry file
idnex.php (default)
<?php
Define (' App_name ', ' APP ');
Define (' App_path ', './app/');
Define (' App_debug ', ' TRUE ');
Require './thinkphp/thinkphp.php ';
?>

app/conf/config.php
<?php
Return Array (
Open grouping
' App_group_list ' => ' index,admin ',
' Default_group ' => ' Index ',

' Tmpl_file_depr ' => ' _ ',///Default template separator is _ rather than folder form
);

Custom Controller
1, delete the original default controller in the Action folder
2, set up two folders, respectively for the foreground and backstage such as index Admin
Visit: Front desk Host/index.php/index backstage host/index.php/admin

Custom profiles (inaccessible to each other, but public configuration can access each other)
1, in host/app/conf/to establish two folders, respectively, for the foreground and background such as index Admin
Configuration: Front desk host/app/conf/index/config.php
Backstage host/app/conf/admin/config.php

Custom functions
1, in host/app/common/to establish two folders, respectively, for the foreground and background such as index Admin
Configuration: Front desk host/app/common/index/function.php
Backstage host/app/common/admin/function.php

Note: The group application does not support {: U ("Form_save")} directly, that is, current controller current method, which writes:
{: U ("/index/index/form_save")}
* Group application [finished]

* * Independent Group configuration
Open:
1, configure the application group first
2, add parameters
' App_group_mode ' =>1,//open Separate group
' App_group_path ' => ' Modules ',//default group path, default: Modules

Common path variables: __root__. ' /’. App_name. ' /’. C (' App_group_path '). ' /’. Group_name. ' /’
New directory structure:
thinkphp//System directory
APP//project directory
Public//Static file directory
index.php//Entry files for all projects

APP:
Modules//Project module ==>admin/action,tpl,model,conf,common; Index/action,tpl,model,conf,common;
Common//Public Common
CONF//Public CONF
LIB//public Lib
TPL//Public TPL
Runtimes//Run time

Public:
CSS JS img

**jquery Asynchronous Commit
$ (' #send-btn '). Click (
function () {
var username=$ (' input[username=username] ');
var password=$ (' Input[password=password] ');

if (username.val () = = ") {
Alert (' User name cannot be empty ');
Username.focus ();
Get user name to focus
Return
}

if (password.val () = = ") {
Alert (' Password cannot be empty ');
Password.focus ();
Get user name to focus
Return
}

Start asynchronous transfer (in the template to be able to parse PHP, can not operate in a separate JS file)
var sendurl= ' {: U (' Index/index/form_save ', ', ')} ';

$.post (Sendurl,{username:username.val (), Password:password.val ()},function (data) {}, ' json ');
}
);

**php Asynchronous Form Processing:
Public Function Form_save () {
Var_dump ($this->isajax ()); Determine if any data is submitted
Var_dump (Is_ajax); [New version] to determine if there is data submission
if (! $this->isajax ()) Halt (' page does not exist ');
$data =array (
' username ' => $this->_post (' username '),
' Password ' => $this->_post (' Password '),
' Time ' =>time ()
);
P ($data);

}

Lesson 11, no record at first.

* Introducing Modules
1, the Verification code module, the core package does not need to manually add, placed in the thinkphp/extend/library/org/util/image.class.php
Import (' ORG. Util.image ');
Image::buildimageverify (4,5, ' PNG ');
Access: This method address can be
To change the verification code, use a JS random number function: Math.random ();
Note: If a pseudo static suffix name appears, you need to add 2 null parameters in {: U (' Admin/login/index '), ","}
Mixed-mode case sensitivity

Verify Code background validation
if (MD5 ($_post[code])!= session (' verify ')) {$this->error (' Authenticode error ');}
if (MD5 ($this->_post[code])!= session (' verify ')) {$this->error (' Authentication code error ');}
if (I (' Code ', ', ', ' MD5 ')!= session (' verify ')) {$this->error (' Authentication code error ');}

2, Pagination class
Import (' ORG.  Util.page '); Import class
$max =m (' User ')->count (); Query total number of articles
$page =new page ($max, 5, ', ' index/index/index/p/');
instantiated objects, Parameters: 1 Total number of lines, 2 per page, 3 page jump parameters, 4 set URL path, useful when grouping, because fewer application group names
$limit = $page->firstrow ', '. $page->listrows; Get first page and total number of pages and set to limit value
$m =m (' User ')->order (' Time DESC ')->limit ($limit)->select (); Find the first page of data
$this->user= $m; Assign data to the foreground template for foreach traversal
$this->page= $page->show (); Assigning paging content to foreground templates

Paging data call in Template: {$page}

**session Save to Database
1, config file add: ' Session_type ' => ' Db ',

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.