Some functions commonly used but not learned by companies , Record the backup .

1, stay Rest In the operation method , have access to $this->_type Gets the type of resource currently accessed , use $this->_method Get the current request type .

2.unset() It's a variable that you define .
because PHP Variables don't need to be predefined to be used .
If you don't unset($color), If you use the same name in the following code $color,PHP I'll use the one I used before ( There is value in it ), If you don't reassign, use , It may affect correctness .

3, Get the value of the field of the object , And turn it into string type , And get rid of the blanks ~~
ToString() Is the way to convert to a string Trim() It's the way to get rid of the spaces on both sides
hold StringBuffer convert to String Type of no avail .trim() Can lead to unexpected results --
use if Sentence judgment is different from what you think
if(returnStr==null||returnStr==""){// No, .trim() That doesn't make sense
//if(returnStr.length()==0){// Judge if the length is zero .trim() It's fine too .

4,md5() Function to evaluate the MD5 hash .

5, call TP Of save Method to update data , If the new data is consistent with the data in the database , Then perform M('table')->save(data) When the method is used , This method returns false. If the data is inconsistent , Data updated successfully , return true

6,ThinkPHP Medium getLastSql function --- Get the last executed SQL sentence

7,import(' Class library name ', ' Starting path ', ' Class library suffix ')
imprt Method has an alias vendor Method , Specifically for importing third-party class libraries , The difference is that the starting path and the default value of the class library suffix are different .

8,substr() Method to extract from a string start The specified number of characters from which the subscript begins .

9,strtotime() Function parses the date time description of any English text as Unix Time stamp .

10,ThinkPHP in C(),D(),S()

1. In concrete Action Method inside , It can be used C() Dynamic configuration of some parameters , It mainly refers to those parameters that have not been used yet . The usage is as follows :
C(' Parameter name '); // Get the parameter value that has been set
C(' Parameter name ',' New parameter values '); // Set the new value

2.D() Use of functions :
Define the model class first , Such as UserModel, And then you can use it D() Functions operate on data . for example :
First in " Your project "\Lib\Model Create a new one called UserModel.class.php Of PHP Script , The contents are as follows :
class UserModel extends Model{}
then , There is no need to add any properties or methods , You can do the following :
$User = D("User"); // Instantiation User object ,User It's a database you created called " Prefix _user" Data sheet for
It can also be used. $User = new UserModel() Instead of , The operation of instantiating objects .
After instantiation , You can add, delete, check and modify the data , Such as :
$User->find(1); // Find the primary key as 1 The record of

3.S() Use of functions :
ThinkPHP All kinds of cache methods are abstracted into a unified cache class to call , and ThinkPHP Unify all caching mechanisms into one S Method to operate , So it's using
Different caching methods don't need to pay attention to specific caching details . Such as :
S('data',$Data); // Use data Identity cache $Data data
S('data',$Data,3600); // cache $Data data 3600 second
$Data = S('data'); // Get cached data

11,ListRows attribute : Return to one ListRows object , representative ListObject All rows of data in the object

12,strtolower() Function to convert a string to lowercase .
notes : This function is binary safe .
Correlation function :
lcfirst() - Convert the first character of a string to lowercase
strtoupper() - Convert strings to uppercase
ucfirst() - Convert the first character of a string to uppercase
ucwords() - Convert the first character of each word in a string to uppercase

13,returnURL($list), The function is to jump back to the page that the user started to request after logging in ( Namely returnUrl The address page of )

14,page:
$list = $Admin->where($extra)->order('id asc')->page($page_num.','.$pagesize)->select();
$this->assign('list',$list);// Assignment data set
$count = $Admin->where($extra)->count();// Query the total number of records that meet the requirements
$Page = new \Think\Page($count,$pagesize);// Instantiate the paging class The total number of incoming records and the number of records displayed per page
$show = $Page->show();// Page display output
$this->assign('page',$show);// Assign value to page output
$this->display();

15,preg_replace — Perform a regular expression search and replace

16,preg_match() Function for regular expression matching , Successfully returns 1 , Otherwise return to 0 .

preg_match() Once the match is successful, the match will stop , If you want to match all the results , You need to use preg_match_all() function .

17,die() Function outputs a message , And exit the current script . The function is exit() Alias for function .

18,is_numeric — Detects whether a variable is a number or a numeric string

19, json_encode() Built in functions (php > 5.2) You can use php Data can be well communicated with other languages and used . The function is to convert the value to json Data storage format .

20,php die( -1 ); What do you mean ? End operation The return value is -1

ThikPHP3.1 Common methods (one) More articles about

  1. The front-end development :Javascript In the array , Common methods of parsing

    The front-end development :Javascript In the array , Common methods of parsing Preface Array yes Javascript An important part of , It can be used to store strings . object . function .Number, It's very powerful . So learn more Array ...

  2. Jquery Element selection 、 Common methods

    One : Common selectors :( Li Changhui ) Basic selector $("#myDiv") // Match the only one with this id The value of the elements $("div") // Matches all elements of the specified name $(" ...

  3. python On the common methods of regularization

    python On the coverage of regular common methods 70% above Last time many friends wrote about using regular expressions , It's not that I don't want to use ( I don't use it very much , Anyone who has seen reptiles before me knows , I use... Directly BeautifulSoup Page tags to ...

  4. C# Webbrowser Common methods and multithreading call

    Set the value of the control /// <summary> /// according to ID,NAME Double judge and set the value /// </summary> /// <param name="tagNa ...

  5. list,tuple,dict,set Common methods

    Python in list,tuple,dict,set Common methods collections Other useful extension types provided by the module from collections import Counter from collect ...

  6. Record yii2-imagine Several common methods

    Record yii2-imagine Several common methods : // Compress Image::thumbnail('@webroot/img/test-image.jpg', 120, 120)->save(Yii::g ...

  7. DOM Summary of common methods

    DOM(Document Object Model: Document object model ) by javascript Part of , It's for accessing and modifying html Document or xml The documentation provides some programming interfaces ,DOM Describe the content of a document in the form of an object , With trees ...

  8. JSP Built in objects and common methods

    jsp Nine built-in objects and four scopes : What is scope Let's see the effect first : The process is like this , We visit index.jsp When , Respectively for pageContext, request, session,applicat ...

  9. java In the collection class Collection Interface Map Familiar with common methods of interface

    1:Map Interfaces provide objects that map keys to values . A map cannot contain duplicate keys : Each key can be mapped to at most one value .Map Interface also provides common methods of collection . 2: because Map The elements in the set are created by key,value, stored , want ...

Random recommendation

  1. WinForm Classes in programs TextBox Custom controls for , Add features that lose focus

    principle : One . In the background code of the control , Add properties of boolean type CanFocus Two . In the constructor of the control , register Enter Event handling method . And in the process , according to CanFocus Property to determine whether focus can be lost , Such as ...

  2. TClientDataSet Design period many times New Field problems

    for the first time New After a few fields , Right-click menu CreateDataSet Later, we need to New Several fields . Right-click menu , First ClearData( No , Will be submitted to the The open dataset cannot execute This New Field operation ), And then in Field editor ...

  3. php Classes that generate random strings and captcha

    There are a lot of php Random number and verification code code code and article , There are few that really apply . Just make one of your own . Start this section with php course   Well , Implementation of the following code , The main purpose is to distinguish one from the other get_code(), the other one create_ch ...

  4. WordPress How thematic frameworks work

    The theme framework can be said to be extremely powerful ! For non-technical WordPress Users , The theme framework makes it possible to build a website that is unique and looks like it's running a customized theme , And for the WordPress For developers , They can ...

  5. ANSI C The common method to get the offset of structure field in

    come from http://blog.chinaunix.net/u2/62910/showart_492571.html Suppose that ANSI C The program defines a program named MyStruct The type of structure , One of them is called MyF ...

  6. net in web.config A single solution ( Other configuration introduction methods )

    Recently, a project needs to write many configuration items , Found in a single web.config The words in it will be messy and difficult to find So I searched and solved it , recorded One .   webconfig The introduction of other config The way <conne ...

  7. Experience sharing : Speed up CocoaPods

    Cocopods  It's an excellent iOS Developed package management tools , covers 7k+ Open source components , The package management library is hosted in Github. For reasons known to all, it's slowing down , Sometimes the following errors are frequently reported : 1 2 3 4 $ ...

  8. Define your own timer (Timer)

    When I was working on a project recently , Yes java.util.Timer Timer class . It is also preliminarily used , I feel good . It's just , in some ways Timer Class cannot meet the needs of the project . example , In the use of Timer when , call schedule() After method ( ...

  9. use golang Implement a proxy pool

    background When writing about crawlers, you will always encounter the problem of being blocked due to too fast crawling speed IP The situation of , At this time, you need to use the proxy . stay https://github.com/henson/ProxyPool Inspired by , Decide to implement a proxy pool on your own . The project has started ...

  10. Hadoop Running traces of

    http://www.cnblogs.com/forfuture1978/archive/2010/11/23/1884967.html A good article about hadoop Basic runtime configuration information