Home  >  Article  >  Backend Development  >  Onthink learning essay, onthink essay_PHP tutorial

Onthink learning essay, onthink essay_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:37838browse

Onthink study essay, onthink essay

-------------------------------- --------(Writing code is not lonely_Xiao Xiaodai)

I used Onthink to write a website that has not been launched yet. It has a slightly incomplete function, and it has not been as powerful and expandable as it should be. It is a bit lame in various places.

However, its powerful data table control is still missing. In view of this, it enters the world of thinphp3.2.2 based development. . .

On the first day, complete the preface, basics, configuration, architecture, and routing reading of the manual.

The next day, complete the controller model reading About the appendix reading

The following is the reading transcript

**************************************************** **

use indicates what namespace is introduced to facilitate direct reference.
Function naming methods use lowercase letters and underscores.
Method naming methods use lowercase letters and underscores. The underscores represent (general private methods)
Functions or methods starting with double underscores are used as magic methods __call
Develop a good habit of using the I function to obtain input variables;
If you encounter problems after updating or changing the environment, the first problem is to clear the Runtime directory;
Convention Configuration application configuration mode configuration debugging configuration status configuration module configuration
Conventional configuration ThinkPHP/Conf/convention.php application configuration is based on the expansion of conventional configuration

Application/Common/Conf/config.php before calling all modules The public configuration file will be loaded first
The optional mode configuration is to add the file config_application name.php in the application configuration folder to run in this mode.
When the debug mode is turned on, ThinkPHP/Conf/debug will be loaded. The
status configuration under .php and application debugging configuration file Application is manual separation
Module configuration Application/current module name/Conf/config.php
Read the configuration file
After defining the configuration file, All use the C method provided by the system (you can use Config) to read or set
Configuration parameter names cannot contain '.' and special characters. Allowed letters, numbers and underscores C method can read the two-dimensional
configuration Configuration parameters are globally valid. Parameter values ​​configured through c are currently valid and will not be written to the database

URL details pathinfo mode description
serverName/index.php (or other application entry files)/module/ Controller/Operation/[Parameter name/Parameter value...]
Public configuration file config.php Public function file function.php can load the path into common_path
Configure in the entry file, if defined There is no need to load Application
3.2.2 The modules and controllers written in the entry file can be automatically generated by default. define('BIND_MODULE','xx') such as

If you want to generate more controllers BUILD_CONTROLLER_LIST constant
// Bind the Admin module to the current entry file
define('BIND_MODULE',' Admin');
define('BUILD_CONTROLLER_LIST','Index,User,Menu');
Manually call the method of the ThinkBulid class to generate the model class ThinkBuild::buildModel 'Role');
//Prohibited access module configuration list of prohibited modules (used to be called by other modules or not open for access). In the default configuration,

prohibits access to the Common module and Runtime module ( The Runtime directory is the default runtime directory), we can add other

prohibited access module lists:
'MODULE_DENY_LIST' => array('Common','Runtime','Api'),
Set access list
Allow access list and default module
'MODULE_ALLOW_LIST' => array('Home','Admin','User'),'DEFAULT_MODULE'

=> ; 'Home',
Single module design is to close multi-module access MULTI_MODOULE=>false

Multiple entry design
Accept parameter binding module
// Bind the Home module to the current entry File $_GET['m'] = 'Home';
define('APP_PATH','./Application/');require './ThinkPHP/ThinkPHP.php';
After binding http:/ /Servername/index.php/home/index/index becomes

http://servername/home.php/index/index (after binding URL does not display home)
URL distinguishad from the case URL_CASE_INSENSITIVEEIVE =>true
Model layer Data layer, logic layer, service layer, and other different model layers When creating Model, Logic, sercive
, it is very convenient to use the D method to call D('User','Logic ');//Instantiating UserLogic D('User') is instantiating

UserModel.
Change the system default view layer DEFAULT_V_LAYER=>'Mobile'; for non-default view layer directory The template is obtained using the T function

number.
The core controller of the Controller layer is completed in the App class inside the system
Event/UserEvent//For the user's event response operation, the Controller is responsible for the external response, and the Event is responsible for the internal response

Internal event response, and can only call A('User','Event') internally;

CBD model
Core(core)+Behavior(behavior)+Driver(driver)

Driver
3.2 further strengthens the driver design in terms of architectural design, replacing the previous engine and mode extensions, and improving the behavior design

The design makes the overall framework more flexible, and because the driver-based design idea is adopted in the functional class libraries that need to write data,

the new framework can easily meet the needs of distributed deployment, and is suitable for Cloud platform support can be implemented more simply.
Behavior
Behavior is a relatively abstract concept, and behaviors will occur in various locations.
Some behaviors are before the application is executed, and some are after the template is output. We use these behaviors as tags

tags (bits), which can also be used as hooks. When the application runs to this tag When , it will be intercepted and the relevant

behaviors will be executed uniformly, which is similar to the concept of "aspect" in AOP programming. Binding related behaviors to a certain tag becomes an AOP-like programming idea.

Think.
Tag bit
The tag function is used to set a certain tag bit. It can be passed in and only accepts one parameter. If you need to pass in multiple parameters,

please use an array, ThinkHook::listen( 'my_tag');
The behavior definition must define the execution entry method run. Due to the influence of the calling mechanism of the behavior, where does the call return?
Behavior Binding After the behavior is defined, it needs to be defined to a certain label to take effect, otherwise it will not be executed. The behavior and tag location need to be defined in the tags.php file of the application

.
return array( 'Tag name 1'=>array('behavior name 1','behavior name 2',...), 'Tag name '

2'=>array(' Behavior name 1', 'Behavior name 2',...), );

For version 3.2.1 or above, it is allowed to set the corresponding class library not to use the namespace.
Configuration file 'APP_USE_NAMESPACE' => false (still required when inheriting and calling system classes)
In version 3.2, instantiate PHP's built-in class library or third-party classes that are not defined using namespaces.
$class = new stdClass(); $sxml = new SimpleXmlElement($xmlstr);
Automatic loading (namespace automatic loading) The namespaces under the Library directory can be automatically identified and located.
In addition to the namespace in the library directory, we can also define other namespaces

autoload_namespace
Improve efficiency by mapping multiple root namespaces with the class library ThinkThink::addMap($map); $ map=array();
Manually import third-party class libraries using the import method to import any class library.
Built-in caching mechanism and running lite files. Features of the new version: Generate static entry files at runtime.

Application mode The application mode is to increase the automatic recognition area

Project compilation application compilation cache (first run cache) - run Lite file (entry static)
------ -------============
Route definition
URL is not in normal mode. To enable routing, you can enable routing in the application (or module) configuration file
/ / Turn on routing 'URL_ROUTER_ON' => true, 3.2 routing is for modules, so the module name cannot be routed. The definition of routing

is usually also in the module configuration file.
Routing expression => Routing address and incoming parameters array('Routing expression','Routing address','Incoming parameters

Number')
Routing expression
Regular Expression/^blog/(d+)$/
Regular expression blog/:id

Exact match $
Public method
-------
Controller
If the method to be operated is a controller method that conflicts with the system keywords, we can set the suffix method

to solve the problem of 'ACTION_SUFFIX' => 'Action', // Operation method suffix
Multi-level controllers are to group controllers
If the instantiated controller is internal, it will be automatically instantiated when parsing the URL address and called. If it is called across controllers

If used, instantiate and then use shortcut method A to call (if it is multi-level, use the second parameter of A). You can instantiate the method when the instance

is instantiated. Before

Preposition and post-position operations (only useful for controllers)

The common ones are _before_index pre-method_after_index post-method. If the pre-post method is not defined, the real template

The output may only be the current operation, and the pre- and post-operations generally do not have any output. If the error operation

is called successfully, there will be no post-operation.
The controller can also bind parameter rules and action parameter binding (can be bound by variable name to implement routing function)
Pseudo-static
URL_HTML_SUFFIX=〉'' Static suffix is ​​recorded to the constant __EXT__ (you can get the current suffix)
URL_DENY_SUFFIX=〉Multiple suffixes that are not allowed to be accessed are separated by |
The priority below is higher than the one above
URL case 'URL_CASE_INSENSITIVE' =>true When the access controller is case-insensitive, capitalize it with _
The system provides the U method to automatically generate the relevant URL address for you

U Similar ( redirect) (URL generation)
In order to match the URL mode used, we need to be able to dynamically generate the corresponding URL address based on the current URL settings. To this end,

ThinkPHP provides a built-in U method, using Due to the dynamic generation of URLs, it can ensure that the project is not affected by the environment during the transplantation process.
U('Address expression',['Parameter'],['Pseudo-static suffix'],['Display domain name'])
[Module/Controller/Operation#anchor@domain name]?Parameter 1=value 1¶meter 2=value 2...
ajax returns ajaxReturn
Can accept the data returned by the variable array. Can handle JSON, JSONP, XML and EVAL. What method can be configured to return

DEFAULT_AJAX_RETURN to return eval can output $data data
Although there is only one letter difference between JSON and JSONP, they are actually not the same thing at all: JSON is a data exchange format, while JSONP is An unofficial cross-domain data exchange protocol. One is the format of describing the information, and the other is the


agreed method of transmitting information.

Jump and redirect
$this->success(prompt information, address, seconds)

----==--=-=
Input Variables
can be obtained and filtered through the I function
I('Variable type.Variable name',['Default value'],['Filter method'],['Additional data source'])
The I function comes with DEFAULT_FILTER, the default is htmlspecialchars (filtering of variables)

Determine the request type (request type)
is_XXX If it is custom AJAX, you need to add a hidden field to tell the background that it is an ajax submission If it is jquery

then it is not necessary. You can configure
empty operation
through VAR_AJAX_SUBMI to automatically call _empty (implementing error pages and some url optimization)
The empty controller system tries to bind the EmptyController
operation to the class ACTION_BIND_CLASS=>'true' To make the classification more detailed,
cannot be omitted. Pre- and post-operations need to be defined in advance.
-=-=-=-=-=-=-=-=-=-=-=-
Model. Uppercase and lowercase _Conversion
Direct instantiation of the model class generally inherits the model class. Model generally has 3 values. Model name data table prefix number

Database connection information
If you want to write native sql code, you only need Instantiate empty just like M();
D (instantiation operation of data model)
The parameter of the method is the name of the model, and it is consistent with the case definition of the model class.
The class does not exist When , the D function will try to instantiate the public module, and can also be used across modules
M (just perform basic CURD operations on the data table) without loading specific model classes, so the performance is higher.
Does not support its own business logic
We often use D method and M method during the instantiation process. The difference between these two methods is that the M method instantiates the model

There is no need for the user to create a new model for each The data table defines the model class. If the D method does not find the defined model class, it will automatically use the M

method.
The field cache includes the field information in the field. You can turn off the field automatic caching by setting DB_FIELDS_CACHE. Add this field in the project configuration

file
Get all the field information of the data table getDbFields(); field( ''/*); Get all the fields to be called

(true).
Use table() to switch data tables; When connecting to the database, you can add a label to the connection
System default rules, Must use model execute write operation query read operation
Continuous operation (chain operation)
where can be used in conjunction with where
data method is written for the database and can also be used for update (save) to determine whether there is The primary key object can be a number

group, object and string. Read operations are available.
Field gets the field. The field exclusion filed(array('user_id','content'),true); is the field other than user_id and

content. Used for writing (security control) and does not allow other writing $model->field('name')-

>create(); means that the legal fields in the form are only the name field , no matter what means the user uses to change or add the submission field of the browser

, it will be blocked directly. Since all other fields we do not want to be determined by user submission, you can define additional fields to write through the

autocomplete function.
filtert (filtering of field content) is somewhat similar to I's judgment $User->data($data)->filter

('strip_tags')->add(); Filter out HTML Tag (functions that support callback types can be functions or closures

Definition)
The having method is to cooperate with the group method to query again from the grouped results.
cache s
comment Comment
The data object created by the Create method is stored in memory and is not actually written to the database until the add

or save method is used. into the database. It is written to the database after add or save, so you can

change the create object before there is any change.

----
find (read a field) select( Read field set) getField (read field value) [Number update setInc setDec]
delete() [It will not be deleted when no conditions are passed in, similar to seve]

When obtaining form mapping data, automatically process the setting to turn on 'READ_DATA_MAP'=>true
You can also use parseFieldsMap to convert the format
Query method
Array '_logic'='OR' Use object mode query stdClass
$map['b'] =array('notlike',array('%thinkphp%','%tp'),'AND');
exp expression query (exp query conditions are not will be treated as a string) All subsequent query conditions can use any syntax supported by

sql, including using functions and field names. Query expressions can be used not only for query conditions, but also for numbers.

Updated.
$data['score'] = array('exp','score+1');//Add 1 to the user's points
$User->where('id=5')-> save($data); // Save modified data according to conditions

Support for multi-language packages L

*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_* _*_12_1
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
Multi-level controller
Instance controller
distinct
(token verification) token
ORM Table mapping to class record mapping to object
AR mode ActiveRecord A simple command
How to enable local session management support with prefix

*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_* _*_12_1

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920432.htmlTechArticleOnthink study essay, onthink essay----------------- ------------------(Writing code is not lonely_Xiao Xiaodai) I wrote a website using Onthink and it has not been online yet. The functions are slightly incomplete, completely...
Statement:
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