ThinkPHP3.2 basic knowledge (1) including file upload,

Source: Internet
Author: User

ThinkPHP3.2 basic knowledge (1) including file upload,
1. content defined in the entry file

// Check the PHP Environment
If (version_compare (PHP_VERSION, '5. 3.0 ',' <') die ('require PHP> 5.3.0! ');
// Enable the debugging mode. We recommend that you enable the annotation of the deployment phase in the development phase or set it to false.
Define ('app _ debug', True );
// Define the application directory
Define ('app _ path', './Application /');
// Introduce the ThinkPHP entry file
Require './ThinkPHP. php ';
// Define the absolute address of the root directory
Define ('root', str_replace ("\", "/", dirname (_ FILE __)));
2. U method parameter rules

('Address expression', ['parameter'], ['pseudo-static suffixes '], ['display domain name'])

Address expression:[Module/controller/Operation # anchor @ domain name]? Parameter 1 = value 1 & Parameter 2 = value 2...
3. How do I determine the request type? What are the two common request methods? What are the parameter rules of the I method?
Determine request type: REQUEST_METHOD
Common Request Methods: Get post
I method parameter rules: I ('variable type. Variable name', ['default default'], ['filter method'], ['additional source'])

Note: The variable type is case insensitive.
Variable names are case sensitive.
The default value and filtering method are optional.

4. Success and Failure, redirection method and parameter rules.
Success ('success condition', 'jump address', 'jump Time ');

Note: The default redirection address of the method is$_SERVER["HTTP_REFERER"],

Error ('error prompting ', 'jump address', 'jump Time ');

Note: The default success method is 1 second, and the error method is 3 seconds.

The Category operation to redirect to the New module
Redirection:$ This-> redirect ('new/category ', array ('cate _ id' => 2), 5,' page Jump ...');

Redirect to the specified URL address

Redirect ('/New/category/cate_id/2', 5,' page Jump ...')
5. Four URL modes. Briefly describe the rules of each form.
Normal Mode: http: // localhost /? Module = home & controller = user & Operation = login & var = value
Pathinfo mode:http://localhost/index.php/home/user/login/var/value/
REWRITE mode: http: // localhost/home/user/login/var/value
Compatibility mode: http: // localhost /? S =/home/user/login/var/value
6. Which configuration files are commonly used in TP? What is the order in which configuration files are loaded?
Configuration File: 1. Convention configuration: Framework built-in configuration file (located inThinkPHP/Conf/convention.php)
2. Application configuration: The application configuration file is the public configuration file that will be loaded first before calling all modules.Application/Common/Conf/config.php)
3. module configuration: Each module automatically loads its own configuration file (located inApplication/current Module name/Conf/config. php)
Loading Sequence: conventional configuration ---> application configuration ---> module configuration
7. Parameter rules of the display method for template Rendering
Display ('[template file]' [, 'encoding '] [, 'output type']);
The template file can be written as follows:

8. The built-in tags of common templates and examples used in the templates are as follows: 5!
1. <foreach name = ''item = ''key = ''> </foreach>
2. <volist name = ''id =''> </volist>
3.<For start = "start value" end = "end value" comparison = "" step = "step value" name = "loop variable name"></For>
4. Comparison labels:
<eq name="name" value="value">value</eq>
5. Range judgment Tag:<in name="id" value="1,2,3">The id is in the range.</in>
6.<if condition="$value eq $k">value</if>
7.
<empty name="name">Name is null</empty>
8.
<Import file = "Js. Util. Array" basepath = "other directories"/> // The start path is the Public directory.
9. Parameter rules contained in the template and Examples
Include label usage:<Include file = 'template expression or template file 1, template expression or template file 2,... '/>

The template expression is defined as follows:Module @ topic/controller/Operation



1. Use a template expression: for example:

2. Use a template file: You can directly include a template file name (including the complete path), for example:
<include file="./Application/Home/View/default/Public/header.html" /
          
3. input parameters: <
Include file = "Public/header" title = "ThinkPHP framework" keywords = "open source WEB development framework"/>
Used in the template:
10. Three Automatic Parameter rules
Field ing: protected $ _ map = array (
'Form name' => 'field name' // map the name in the form to the field name in the data table
);
Automatic Verification: protected $ _ validate = array (
Array ('field name', 'verification rule', 'prompt information', 'verification condition', 'additional rule', 'verification Time '),
);
Automatic completion: protected $ _ auto = array (
Array ('field name', 'verification rule', 'verification time', 'additional rule '),
);
11. Give an example to describe the full process code called by the upload class in the Controller (requires the code containing the controller and all the code for adding data to the database in the model class), and describe the content to be paid attention to in the form!
Model class:
Public function doUpload (){
If (empty ($ config )){
$ Config = array (
'Maxsize' => 3145728,
'Rootpath' => './Public/', // Save the root path. You must set it again. Otherwise, the root path cannot be found.
'Savepath' => 'uploads /',
'Savename' => array ('uniqid ',''),
'Exts' => array ('jpg ', 'gif', 'png', 'jpeg '),
'Autosub' => true,
'Subname' => array ('date', 'ymmd '),
);
}
$ Upload = new Upload ($ config );
$ Info = $ upload-> upload ();
If (! $ Info ){
$ This-> error = $ upload-> getError ();
Return false;
}
Foreach ($ info as $ key => $ v ){
$ Pic [$ key] = $ v ['savepath']. $ v ['savename'];
}
Return $ pic;
}
Controller:
$pic=$this->work->doUpload();
$ _ POST ['image field'] = $ pic ['image field']; // Add it to the database
Note:
1. <form action = "" method = "post" enctype = "multipart/form-data"> </form>
2. <input type = "file" name = "" value = ">
3. Pay attention to the rootPath path.
Note: To save the root path, you must reset it. Otherwise, the root path cannot be found.



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.