1, how to open the debug mode, open debug mode What is the use?
Open Debug mode suggest the development phase to open the deployment phase Comment or set to Falsedefine (' App_debug ', True);
The use of open Debug mode: To facilitate the timely detection of hidden problems and analysis, solve problems.
2. How do I define an empty controller and a null operation?
Empty operation:
<?phpnamespace home\controller;use think\controller;class Citycontroller extends controller{public function _ Empty ($name) {
The operation of all cities is resolved to the city method $this->city ($name); }
Note that the city method itself is the protected method protected function City ($name) {
And $name this city-related deal with Echo ' current city '. $name; }
NULL Controller:
<?phpnamespace home\controller;use think\controller;class Emptycontroller extends controller{public function Index () { //According to the current controller name to determine the operation to perform that city $cityName = controller_name; $this->city ($cityName); } Note that the city method itself is the protected method of protected function City ($name) { //and $name is related to the processing of the echo ' current cities '. $name; }}
3, how to define the pre-and post-operation parameters of the controller?
Pre-action: _before_ operation name: _after_ operation name
Example:
<?phpnamespace home\controller;use think\controller;class Indexcontroller extends controller{ //Pre-operation method Public Function _before_index () { echo ' before<br/> '; } Public Function Index () { echo ' index<br/> '; } Post-operation method public function _after_index () { echo ' after<br/> '; }}
4. Please write out the rules of auto-authentication, require checking the Rules of password field (PWD) when modifying and adding, and checking whether or not it is empty, the rule is: the password should contain uppercase and lowercase letters and numbers and the length should be at least 6 bits;
Protected $_validate=array ( array (' Password ', ' Require ', ' password cannot be empty! '), Array (' Password ', '/^[a-za-z0-9]{6}$/', ' password cannot be less than six bits! ', 0, ' regex ', 3), )
What are the 5.3 query methods and 8 kinds of query method?
3 Ways to query: strings, arrays, objects
8 Query methods: Expression query, quick query, interval query, combinatorial query, statistical query, subquery, SQL query, dynamic query
6. Write a sample code for a composite query in a combination query;
$where [' name '] = Array (' Like ', '%thinkphp% '); $where [' title '] = Array (' Like ', '%thinkphp% '); $where [' _logic ' ] = ' or '; $map [' _complex '] = $where; $map [' id '] = array (' GT ', 1);
7. Please write the operation that can be repeated in the coherent operation;
Where the definition string, array, and object used to query or update conditions
Join support strings and arrays for queries
Union supports strings, arrays, and objects for the Union of Queries
Scope is used for naming range strings, arrays
Bind is used for data-bound manipulation arrays or multiple parameters
8. The principle of automatic loading;
Automatically navigate to class library files through the class's namespace
The two filtering rules commonly used in 9.I method and their meanings are explained.
1.htmlspecialchars:把一些预定义的字符转换为 HTML 实体.
Use syntax: string: Required. Specifies the string to convert.
Quotestyle: Optional. Specifies how to encode single and double quotation marks.
Character-set: Optional, String value that specifies the character set to use.
Htmlspecialchars (String,quotestyle,character-set)
Example:
2.strip_tags:剥去 HTML、XML 以及 PHP 的标签。
Syntax: Strip_tags (String,allow)
String: Required. Specifies the string to check.
Allow: Optional. Specifies the allowable label. These tags are not deleted.
Example:
<?phpecho strip_tags ("Hello <b><i>world!</i></b>");? >
Output: Hello world!
Filter methods written in the model:
$this->data($data)->filter(‘strip_tags‘)->add();
10. Two parameter rules for template assignment;
String: $this-assign (' show ', $show);
Array: $this-assign ($arr);
11. How do I modify the delimiter of a template label?
' Tmpl_l_delim ' = ' <{', ' Tmpl_r_delim ' and ' ;} '
12. Template variables in the template output, strings, arrays, objects are how to output;
String: <{$name}>
Array: <{$data [' Name ']}>
Object: <{$data:name}> or <{$data->name}>
13. How to turn on batch verification;
protected $patchValidate = true;
14. How do I get the Model class error message in the controller?
D (' table name ')->geterror ();
15. Brief introduction to the MVC process, the benefits of single entry mode:
Single entry mode advantages: safe, flexible. Centralized security processing, access to statistics and other unified control.
16. Why should the PHP version be judged in the import file, and what is the version of PHP required for TP?
Because ThinkPHP3.2 introduces the concept of namespaces, PHP5.3 above (including PHP5.3) is supported
PHP version cannot be less than 5.3.0
17. What is the controller definition rule (including controller name, controller class name, and controller class file name), one example is given.
Controller name: Capitalize first letter. Example: Index
Controller class Name: Controller name +controller. Example: Indexcontroller
Controller class file name: Controller class name +.class.php. Example: IndexController.class.php
18 naming rules for custom model classes, including model names, model class names, and model class filenames;
Model name: Based on the table name, remove the first letter of the table prefix, if there is an underscore, remove the underscore after the first letter uppercase. (Large Hump method) Example: User
Model class Name: Model name +model. Example: Usermodel
Model class file name: Model class name +.class.php example: UserModel.class.php
19. What are the two ways to generate a new module?
1.define (' Bind_module ', ' Admin ');
2. Copy the Home module
20. What are the five instantiation modes of the model class, each of which is cited as an example;
1. Instantiate an empty model class: $model =new models ();
2. Instantiate the underlying model class: $model =new model ([' model name '],[' data table prefix '],[' database connection information ']);
3.M method Instantiation of the underlying model class: $model =m ([' Model name '],[' data table prefix '],[' database connection information ']);
4. Instantiate a custom base model class: $model =new Model class operation name ([' Model name '],[' data table prefix '],[' database connection information ');
5.D method instantiates a custom base model class: $model =d ([' Model name '],[' data table prefix '],[' database connection information ']);
What is the equivalent full native method for setting default values for the 21.I method?
Example: $id =isset ($_get[' id ")? $_get[' id ']: ';
22. The difference between implicit query and display query, which is more efficient, please give examples of two kinds of writing rules of Query method;
Difference: Display query can improve query speed, high efficiency
Show queries more efficiently
Explicit query: Field for example: $this->field (' name ', ' pwd ')->select ();
Implicit query: For example: $this->select ();
23. Specify how the field updates and inserts are coherent, with examples describing how to insert and modify the specified fields;
Update: setfield Example:$User-> where(‘id=5‘)->setField(‘name‘,‘ThinkPHP‘);
Insert: Add ()$User->data($data)->add();
24. How is the template theme called, and How does the view-level catalog need to be adjusted after using the template theme?
Template Theme Calls:$this->theme(‘blue‘)->display();
View-level Catalog:--view
--blue//Template theme
--index//Controller name
--color.html//Template Theme page
25. What is defined in the portal file
Detecting PHP environments
if (Version_compare (php_version, ' 5.3.0 ', ' < ') die (' Require PHP > 5.3.0! ');
Open Debug mode suggest the development phase to open the deployment phase comment or set to False
Define (' App_debug ', True);
Defining the App Catalog
Define (' App_path ', './application/');
Introducing the thinkphp entry file
Require './thinkphp/thinkphp.php ';
Defines the absolute address of the root directory
Define (' ROOT ', str_replace ("\ \", "/", DirName (__file__)));
Parameter rules for 26.U methods
(' Address expression ', [' parameter '],[' pseudo static suffix '],[' Display domain name '])
Address expression:[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...
27. How to determine the type of request, what are the two common request methods, the parameter rules of the I method?
Judging request type : Request_method
Common Request Mode : Get post
parameter rules for the I method : I (' variable ' type. Variable name ', [' Default '],[' Filter method '],[' extra data source '])
Note: Variable types are not case-sensitive.
Variable names are strictly case-sensitive.
Both the default and filtering methods are optional parameters.
28. Success and failure, redirect the method of jump and parameter rules.
success (' Success condition ', ' Jump address ', ' Jump Time ');
Note: The default jump address for the method is $_server["Http_referer" ,
Error (' Error prompt ', ' Jump address ', ' Jump Time ');
Note: The default Wait time success method is 1 seconds, the error method is 3 seconds
Redirect to the category action of the new module
Redirect:$this->redirect(‘New/category‘, array(‘cate_id‘ => 2), 5, ‘页面跳转中...‘);
重定向到指定的URL地址
redirect(‘/New/category/cate_id/2‘, 5, ‘页面跳转中...‘)
Four modes of 29.URL, outlining the rules for 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
What are the 30.TP common configuration files? What is the order in which the configuration files are loaded?
Profiles: 1. Custom configuration: Framework built-in configuration file (located ThinkPHP/Conf/convention.php )
2. Application configuration: The Public profile (which is located by default) that will be loaded first before all modules are called Application/Common/Conf/config.php
3. Module configuration: Each module will automatically load its own configuration file (located Application/当前模块名/Conf/config.php )
Load order: Custom Configuration---> Application configuration---> module configuration
31. Template rendering parameter rules for display methods
Display (' [Template file] ' [, ' character encoding '] [, ' Output type ']);
The template file is written in the following ways:
32. Common template built-in tags and examples used in the template, cite 5!
1.<foreach name= ' item= ' key= ' ></foreach>
2.<volist name= ' id= ' ></volist>
3.<for start="开始值" end="结束值" comparison="" step="步进值" name="循环变量名" ></for>
4.比较标签:<eq name="name" value="value">value</eq>
5.范围判断标签:<in name="id" value="1,2,3">id在范围内</in>
6.<if condition="$value eq $k">value</if>
7.<empty name="name">name为空值</empty>
8.<import file="Js.Util.Array" basepath="其他目录" />//起始路径是Public目录
33. Template contains the parameters of the rules and examples of instructions
Include tag usage:<include file=‘模版表达式或者模版文件1,模版表达式或者模版文件2,...‘ />
Template expressions are defined as: module @ theme/controller/operation
1.使用模板表达式:例如:
2.使用模板文件:可以直接包含一个模板文件名(包含完整路径),例如:<include file="./Application/Home/View/default/Public/header.html" /
3.传入参数:<include file="Public/header" title="ThinkPHP框架" keywords="开源WEB开发框架" />
模板中使用:
34. Three main automatic parameter rules
Field mappings: Protected $_map=array (
' Name in the form ' = ' and ' field name '//' map the name name in the form to the field name in the data table
);
Automatic Verification: protected $_validate=array (
Array (' Field name ', ' Validation rule ', ' hint info ', ' validation condition ', ' additional rule ', ' verification time '),
);
Auto-complete: protected $_auto=array (
Array (' Field name ', ' Validation rule ', ' validation time ', ' additional rules '),
);
35. Describe the entire process code that the upload class invokes in the controller (requires the code that contains the controller and the entire code of the model class to add data to the database), and describes what needs attention in the form!
Model class:
Public Function Doupload () {
if (empty ($config)) {
$config = Array (
' maxSize ' = 3145728,
' RootPath ' = ' ./public/',//Save the root path, be sure to reset it, or you will not find the root path
' Savepath ' = ' uploads/',
' Savename ' = = Array (' uniqid ', '),
' exts ' = = Array (' jpg ', ' gif ', ' PNG ', ' jpeg '),
' autosub ' = true,
' subname ' = Array (' Date ', ' YMD '),
);
}
$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[' picture field ']= $pic [' Picture field '];//added to the database
What to note in the form:
1.<form action= "" method= "Post" enctype= "Multipart/form-data" ></form>
2.<input type= "File" name= "value=" ">
3. Note the RootPath path.
Note: The stub path must be reset, otherwise the root path cannot be found
ThinkPHP3.2 Basic Knowledge