Home > PHP Framework > ThinkPHP > Thinkphp interview questions and answers

Thinkphp interview questions and answers

coldplay.xixi
Release: 2020-08-10 16:52:53
forward
8285 people have browsed it

Thinkphp interview questions and answers

1. How tounderstand the single entry file in TP?

## Answer: ThinkPHP uses a single entry mode for project deployment and access. No matter what function is completed, a project has a unified Not necessarily the only entrance). It should be said that all projects start from the entry file, and the entry files of all projects are similar. The entry file mainly includes:

Define the framework Path, project path and project name (optional)

Define related constants for debug mode and run mode (optional)

Loading the framework entry file (required)

2.MVC layering in ThinkPHP What is it? (understand)

 MVC is a method of separating the logical layer and presentation layer of an application. ThinkPHP is also based on the MVC design pattern. MVC is just an abstract concept with no particularly clear regulations. The MVC layering in ThinkPHP is roughly reflected in:

# # Model (M): The definition of the model is completed by the Model class.

Related topic recommendations:
2020 thinkphp interview questions and answers (complete collection)

Controller (C): Application controller (core controller App class) and Action controller both assume the role of controller. Action controller completes business process control, while application controller is responsible for scheduling control.

View (V): It consists of View class and template file. The template is 100% separated and can be previewed and produced independently.

But in fact, ThinkPHP does not depend on M or V, which means it can work without a model or view. It doesn’t even rely on C. This is because ThinkPHP also has a master controller on top of Action, the App controller, which is responsible for the overall scheduling of the application. In the absence of C, view V must exist, otherwise it is no longer a complete application.

In short, ThinkPHP’s MVC model only provides a means of agile development, rather than sticking to MVC itself.

3.How to understand the behavior in ThinkPHP 3.0 architecture (core behavior driven)?

answer: Core Behavior Driven

TP official abbreviation is: CBD

Core: It is the core code of the framework, an indispensable thing. TP itself is a framework developed based on the MVC idea.

Behavior: Behavior plays a decisive role in the architecture of the new version of ThinkPHP. On top of the core of the system, it is set Many tag extension bits, and each tag position can in turn perform its own independent behavior. This is how behavioral extensions were born, and many system functions are also completed through built-in behavioral extensions. All behavioral extensions are replaceable and additive, thus forming the basis for the assembly of the underlying framework.

Driver: database driver, cache driver, tag library driver and template engine driver, as well as external class extensions.

Frame, that is, framework. In fact, it is a semi-finished product of a certain application, a set of components for you to choose and use to complete your own system. To put it simply, you use the stage set up by others and you perform. Moreover, frameworks are generally mature, continuously upgraded software.

4. How does ThinkPHP prevent SQL injection? (Understanding)
 
##(1) Try to use array mode for query conditions. It is a safer way;

  (2) If string query conditions must be used as a last resort, use the preprocessing mechanism ;

  (3) Turn on data field type verification, and you can force conversion of numerical data types; (This has been mandatory since version 3.1 Field type verified)

 (4) Use automatic verification and automatic completion mechanisms for custom filtering for applications;

(5) Use field type checking, automatic verification and automatic completion mechanisms to avoid malicious data input.

5. How to enable debugging mode? What are the benefits of debug mode?

 Enabling debugging mode is very simple, just add a line of constant definition code to the entry file :

<?php
 
      //开启调试模式
 
      define(&#39;APP_DEBUG&#39;, true);
 
      //加载框架入口文件
 
      require &#39;./ThinkPHP/ThinkPHP.php&#39;;
Copy after login

 After completing the development phase and deploying to the production environment, you only need to delete the debug mode definition code to switch to deployment mode. After turning on debugging mode, the system will first load the system default debugging configuration file, and then load the project's debugging configuration file. The advantages of debugging mode are:

  Turn on logging, any error information and debugging information will be recorded in detail to facilitate debugging;

## Turn off the template cache, and template modifications can take effect immediately;

Record SQL logs for easy analysis SQL;

Turn off field caching, data table field modifications will not be affected by the cache;

Strictly check file case (even on Windows platform) to help you detect Linux deployment problems in advance;

It can be conveniently used in different stages of the development process, including development, testing, demonstration and other necessary situations. Different application modes can be configured with independent project configuration files.

6. What configuration modes are supported in TP? priority?

 ThinkPHP has created its own unique hierarchical configuration mode in project configuration, and its configuration level is reflected in:

## Conventional configuration->Project configuration->Debug configuration->Group configuration->Extended configuration-> ;Dynamic configuration

The above is the loading sequence of the configuration file, because the subsequent configuration will overwrite the previous configuration of the same name (if it is not effective premise), so the order of precedence is from right to left.

7. What are the URL patterns in TP? Which is the default?

 ThinkPHP supports four URL modes, which can be defined by setting the URL_MODEL parameter, including normal mode, PATHINFO, REWRITE and compatibility mode.

## The default mode is: PATHINFO mode, set URL_MODEL to 1

#8. What are the system variables in TP? How to get system variables?

Method to obtain system variables:

 You only need to call the following method in Action:

$this->Method name ("Variable name",["Filtering method"],["Default value"])

#9ThinkPHP in the framework What is the difference between D function and M function?

## Answer: MMethod instantiating the model does not require the user to define a model class for each data table. The D method can automatically detect the model class. If a custom model class exists, instantiate the custom model class. If it does not exist, then The M method will be automatically called to instantiate the Model base class. At the same time, models that have been instantiated will not be instantiated repeatedly (single case mode).

Related learning recommendations:
thinkphp

The above is the detailed content of Thinkphp interview questions and answers. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template