thinkphp Summary turn, thinkphp summary
After a few projects with thinkphp, feel this framework pretty good, very suitable for their own logic habits, development is also fast, hehe, summed up some of the items commonly used in the East, I hope to beginners TP friends help!
Conventions:
Such as:
Defining the Controller class
Changes to the record:
Record query
$User->getdbfields ()//Get the current data field
$Model = new Model ()//Instantiate a model object without any data table
$objrs = $Model->query ("select * from Think_userwhere Status=1")//Custom query
Template:
$this->assign (' name ', $value); Use the Assign method in the Action class to assign a value to the template variable, regardless of which variable type is uniformly used assign assignment
$this->display ()//Output template file
Batch Assignment
Template Tags:
{} or {//comment content}//Template comment
To facilitate template definition, the output template variable can be output in the following uniform way, regardless of whether it is an array or an object:
Using functions:
System variables
Quick output
Include external files
Loop output
Template assignment:
Template definition:
Note the meaning of the name and ID representation
Output even record
Output key
Sub-loop output
Switch Label
Compare labels
If label
C operation
A operation
D operation
s operation
F operation
(In Parameter1 INTEGER)
BEGIN
DECLARE variable1 CHAR (10);
IF Parameter1 =
SET variable1 = ' birds ';
ELSE
SET variable1 = ' beasts ';
END IF;
Insert into table1 VALUES (variable1);
END
Thinkphp System Constants
Think_path//thinkphp system directory
Config_path//project configuration file directory
MEMORY_LIMIT_ON//Whether there is a memory usage limit
Pre-defined constants
Upload Overview
Basically transfer function
Bulk upload
It is important to note that the UploadFile upload class is not used for multiple file uploads
Ajax File Upload
Automatically generate thumbnails
After Setup, the system will automatically generate thumbnails in the same format after uploading. The default thumbnail path for the system is the directory where the files are uploaded, and _thumb is added later in the file to identify the thumbnail files. The thumbnail path can be configured in the project configuration file.
Generate multi-thumbnail images
The example above shows a three-size thumbnail, with the suffix added after the thumbnail filename and the width and height of the three thumbnails.
More Upload Settings
Thinkphp also provides the upload settings interface for the UploadFile class in action, which allows for more parameter settings to be uploaded and controlled by the client.
Below is a list of the main parameters, and more parameters can refer to the _upload method in the action class of the framework.
Set Overlay Upload
Set allow file types to be uploaded
Upload files to save directory, be aware of setting writable permissions
Upload file name naming rules, support functions, such as time uniqid com_create_guid system default to uniqid ensure that the upload file name is not duplicated, if there is no setting function, use the rule string as the upload file name
Set Upload file size
Set the Upload data table, the default upload data is recorded in the current module table Set the data number for the upload file, usually without setting it, unless specifically required
Set the upload user ID, usually not set, the system automatically get the current login user number
Original: http://blog.sina.com.cn/s/blog_813e149b01010o3z.html
thinkphp how to achieve jump to other sites
5.15 redirects
The redirect method of the Action class enables page redirection.
The parameter usage of the redirect method is consistent with the use of the U function (refer to the URL Generation section above), for example:
The above usage is to jump to the category operation of the news module after 5 seconds, and display the words in the page jump, and redirect changes the current URL address.
If you simply want to redirect to a specified URL address instead of to a module, you can redirect directly using the redirect method, for example:
The first parameter of the redirect method is a URL address.
5.14 page Jump
In application development, you will often encounter a number of jump pages with hints, such as the success of the operation or the error page, and automatically jump to another target page. The action class of the system contains two jump methods success and error, which are used for page jump hints, and can support Ajax submissions. The method of use is simple, for example, as follows:
Success and the error method have a corresponding template, and can be set, the default setting is two methods corresponding to the template are:
Template files can use template tags, and you can use the following template variables:
$msgTitle: Action Title
$message: Page tip Information
$status: Operation Status 1 indicates success 0 indicates failure specific rules can also be defined by the project itself
$waitSecond: The Jump Wait time unit is seconds
$JUMPURL: Jump page Address
The success and Error methods automatically determine whether the current request is an AJAX request, and if it is an AJAX request, call the Ajaxreturn method to return the information, referring back to the Ajax return section.
These things thinkphp3.0 manual, download the manual to see
How to connect a database in thinkphp [go]
thinkphp How to connect database operations database, we will create a model. Before you say the model and action, explain the location where the model and action are saved. The model is saved in the Lib/model folder in the program directory, and the action is saved in the Lib/action folder in the program directory. thinkphp system default Model rule is this: Model file Civilization name is similar to "model class name +model.class.php, and the model default operation database table name is our definition in config.php db_prefix+ Model class name, model class name and file name need to be capitalized "in the model file, define a class, extend the model class, the general syntax is as follows class name model extends model{} Well, now let's define a model. Because our database table name is Cms_article,class Articlemodel extends model{} file is saved as ArticleModel.class.php. Do not write anything, a model has been defined to complete. So now, let's continue with our action knowledge. The action and model many of the rules are very close, the difference is that the action does not directly manipulate the database, but need to use model to operate the database. Now let's define an action to complete the operation. Class Indexaction extends Action{function index () {$Article = D ("article");}} Save the file as IndexAction.class.php. OK, now we refresh the homepage, if there is no hint, then congratulations, the database connection model, the action definition is normal. The D method in action is to call Model,article the model class in the ArticleModel.class.php that we just defined-that is, while defining the model, we have completed the connection to the database and the operation of the database table. Ready ~
http://www.bkjia.com/PHPjc/844682.html www.bkjia.com true http://www.bkjia.com/PHPjc/844682.html techarticle thinkphp Summary turn, thinkphp summary with thinkphp did a few projects, feel this framework pretty good, very suitable for their own logic habits, developed also fast, hehe, summed up a number of projects ...