Onthink Learning Essays, Onthink essays _php Tutorials

Source: Internet
Author: User

Onthink Study Essays, Onthink essays


-------------------------------------(Write code not lonely _ small generation)

With Onthink wrote a website temporarily did not go online function slightly not all, completely did not play out due to the strong expansion of the place, a little bit lame.

But its powerful data-sheet control is still a significant drain, given this foray into the development-based thinphp3.2.2 world ...

First day complete manual preface, basics, configuration, architecture, routing reading.

Next day Complete controller model read about appendix Reading

The following is a reading of the accompanying record

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

Use indicates what namespaces are introduced to facilitate direct referencing
Method of naming a function using lowercase letters and underscores
The name of the method is used for lowercase letters and underscores that are represented by the (general private method)
A function or method preceded by a double underscore as a magical method __call
Develop a good habit of using the I function to get input variables;
After updating or environment change, the first problem is emptying the runtime directory;
Custom Configuration Application configuration mode configuration Debug Configuration state Configuration module configuration
Custom configuration thinkphp/conf/convention.php application configuration is an extension of the Convention-based configuration

application/common/conf/config.php public configuration files that are loaded before all modules are called
The optional mode configuration is to add a file Config_ app name that runs this mode in the app configuration folder. php
Debug mode on will load thinkphp/conf/debug.php and apply Debug configuration file application under the
State configuration is manual separation
Module configuration application/Current module name/conf/config.php
Reading configuration Files
Once you have defined the configuration file, you can use the system to provide a C method (with config) to read or set
Configuration parameter name cannot contain '. ' and special characters, allowed letters, numbers and underscores the C method can read two-dimensional
The configuration configuration parameter is globally valid and the parameter value configured through C is currently effectively not written to the database

URL Details pathinfo Mode description
servername/index.php (or other application entry file)/module/controller/operation/[parameter name/parameter value ...]
Common configuration file config.php Common function file function.php can load paths into Common_path
In the Portal file configuration, if the definition of application below does not need to load application
3.2.2 Write in the portal file can be automatically generated by default module, controller. Define (' Bind_module ', ' xx ') as

To generate more controllers Build_controller_list constants
Binding the Admin module to the current portal file
Define (' Bind_module ', ' Admin ');
Define (' Build_controller_list ', ' index,user,menu ');
Call the Think\bulid class method manually to generate the model class \think\build::buildmodel

(' Admin ', ' Role ');
Block Access module configuration list of blocked modules (for calls by other modules or not open access), in default configuration

is to disable access to the Common module and runtime module (runtime directory is the default runtime directory), we can add additional

Disable access to the list of modules:
' module_deny_list ' = = Array (' Common ', ' Runtime ', ' Api '),
Set up access lists
Allow access to lists and default modules
' module_allow_list ' = = Array (' Home ', ' Admin ', ' User '), ' Default_module '

= ' Home ',
Single module design is to turn off multi-module access Multi_modoule=>false

Multi-entry Design
Accept parameter Binding module
Bind Home Module to 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 (url not showing home after binding)
URL Case-sensitive url_case_insensitive=>true
Model layer data layer, logical layer, service layer, and so on different model layer create model,logic,sercive
It is convenient to call D (' user ', ' Logic ') with the D method when calling, and//instantiating userlogic D (' user ') is instantiated

Usermodel.
Change the system default view layer default_v_layer=> ' Mobile '; for templates that are not the default views layer directory get the use of T-function

Number acquisition.
Controller Layer Core controller is completed within the system's app class
event/userevent//for user Incident Response Operations The Controller is responsible for the external response of the event responsible for internal

And only internally calls a (' User ', ' event ');

CBD model
Core (Kernel) +behavior (behavior) +driver (driver)

Driver (Drive)
The 3.2 architecture design reinforces the drive design, replaces the previous engine and pattern extensions, and improves the behavior

To make the framework whole more flexible, and because of the need to write data in the functional class library has adopted the driving design idea,

So that the new framework can easily meet the needs of distributed deployment, the support of the cloud platform can be more simple implementation.
Behavior (behavior)
Behavior is a relatively abstract concept, and each location will have the behavior of the generation.
Some of the behavior is before the application is executed, and some are after the template output, we make these behavior as the location of the

sign (bit), you can also become a hook, when the application runs to this tag, it will be intercepted, unified implementation of the relevant

Behavior, similar to the concept of "tangent" in AOP programming, the binding behavior of a certain tag becomes a kind of class AOP programming thinking

Think.
Label bit
The tag function is used to set a label bit, can pass in and accept only one parameter, if you need to pass in multiple parameters,

Please use an array, \think\hook::listen (' My_tag ');
The behavior definition must define the Execute entry method run, which is returned by the invocation mechanism of the behavior, where the call is effected.
The behavior binding behavior is defined and needs to be defined to a tag bit to take effect, otherwise it will not be executed. Need to be applied

The behavior definition file in the tags.php file defines the location of the behavior and labels.
return Array (' tag name 1 ' =>array (' behavior name 1 ', ' Behavior Name 2 ',...), ' tag name

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

3.2.1 Versions above, allow setting the corresponding class library does not use namespaces.
Config file ' app_use_namespace ' = False (inherited calls to system class, still required)
In version 3.2, instantiate a PHP built-in class library or a third-party class that does not use a namespace definition.
$class = new \stdclass (); $sxml = new \simplexmlelement ($XMLSTR);
Automatic loading (automatic namespace loading) the namespaces below the Library directory can be automatically identified and positioned.
In addition to namespaces in the Library directory, we can also define additional namespaces

Autoload_namespace
Improve efficiency Class Library mapping multiple root namespaces think\think::addmap ($map); $map =array ();
Manual third-party class library Import the import method imports any class library.
Built-in caching mechanism and running Lite File New version of the feature runtime generates a static portal file.

Application Mode application mode is to increase the automatic recognition area

Project compilation application compilation cache (first run cache)--run Lite file (portal static)
-------------===========
Route definition
URL is not in normal mode, enabling routing can be enabled in the application (or module) configuration file
Open route ' url_router_on ' =〉true, 3.2 route is for module so module name cannot be routed, definition of route

Usually also in the module configuration file.
Route expression =〉 routing address and incoming parameter array (' route expression ', ' Routing address ', ' incoming parameter '

Number ')
Route expression
Regular Expression/^blog\/(\d+) $/
Rule expression Blog/:id

Exact Match $
Public methods
-------
Controller
If the method to be manipulated is a controller method that conflicts with the system's keywords, we can set the suffix method

Resolve ' action_suffix ' = ' action ',//operation method suffix
Multilevel controller is to group the controller
If the instantiation controller is internal, it is instantiated automatically when the URL address is resolved and called if the cross-controller

Then instantiate and then use the shortcut method a call (the second parameter of a if it is multi-layered) can be used in the instance

The method is instantiated at the time of the process.

Pre-and post-operation (only useful for controllers)

It is common for the _before_index method to _after_index the post-placement method if there is no pre-built method defined

The board output may be just the current operation, and the front and rear operations generally do not have any output. Invoke Error success

There is no post-operation.
The controller can also bind the parameter rule action parameter bindings (by variable name can be bound to implement the routing function)
Pseudo-Static
url_html_suffix=〉 ' static suffix record to constant __ext__ (can get the current suffix)
Url_deny_suffix=〉 not allowed to access multiple suffixes separated by |
The following priority level is higher than the above
URL case ' url_case_insensitive ' =>true case-insensitive when access controller capitalization to be added _ before
The system provides U method to automatically generate the relevant URL address for you

U similar (redirect) (URL generation)
To match the URL pattern used, we need to be able to dynamically generate the corresponding URL address based on the current URL settings,

The thinkphp built-in provides a U method for dynamic URL generation to ensure that the project is not affected by the environment during the migration process.
U (' address expression ', [' parameter '],[' pseudo static suffix '],[' Display domain name '])
[module/Controller/Operation # Anchor point @ domain name]? parameter 1= value 1& parameter 2= value 2 ...
Ajax return Ajaxreturn
The data returned by the variable array can be accepted to govern JSON, JSONP, XML, and eval can be configured with what party

Return Default_ajax_return for eval to output $data data
JSON and JSONP Although there is only one letter difference, but in fact they are not the same thing: JSON is a number

The JSONP is an unofficial cross-domain data exchange protocol. One is a description of the information format, a

It's information delivery.


The contract method.

Jump and redirect
$this->success (Hint message, address, number of seconds)

----==--=-=
Input variables
Variable acquisition and filtering can be done through the I function
I (' Variable type ', ' variable name ', [' Default '],[' Filter method '],[' extra data source '])
The I function comes with Default_filter the default is htmlspecialchars (variable filter)

Determine request type (Request type)
Is_xxx if it's a custom Ajax, you need to add a hidden field to tell the background that Ajax commits if it's jquery.

Words are not required. Can be configured via VAR_AJAX_SUBMI
Empty operation
Automatic Call _empty (Implementation error page and some URL optimizations)
The empty controller system tries to set the Emptycontroller
Operation binding to Class action_bind_class=〉 ' true ' points more detail cannot be omitted
Pre-post operations need to be defined in advance
-=-=-=-=-=-=-=-=-=-=-=-
Model Casing and _ conversions
Model class direct instantiation generally inherit the model class model generally has 3 values the number of the name data table prefix

Data Base connection Information
If you want to write native SQL code, you only need to instantiate the empty m ();
D (instantiation of the data model)
The parameter of the method is the name of the model and is consistent with the case definition of the model class.
When the class does not exist, the D function attempts to instantiate the public module below, and can also be used across modules
M (a basic curd operation on a data table only) does not require the loading of a specific model class, so performance is higher.
does not support its own business logic
In the process of instantiation, we often use the D method and the M method, the difference between the two methods is that the M method instantiation modulo

Type does not require the user to define a model class for each data table, and if the D method does not find a defined model class, it will automatically use the M

Method.
Field cache includes field information inside fields can be set Db_fields_cache to close field Auto-cache in project configuration

Add this field in the file
Gets all field information for the data table Getdbfields (); Field ('/*); Gets all fields to invoke field

(true).
Switch data table with table (); When connecting to a database, you can add an identity to the connection
System default rules, you must use the model execute write operation to query the read operation
Coherent operation (chained operation)
Where can be used with where
The data method is written for the database and can also be used for update (save) to determine whether a primary key object can be a number

Groups, objects, and strings. Read operation is possible.
Field Get field, exclude filed (Array (' user_id ', ' content '), true); user_id and

Fields outside of the content. For write (security control) does not allow other writes $model->field (' name ')-

>create (); means that the legal field in the form is only the Name field, regardless of the means by which the user changed or added the browser

, the submission fields are masked directly. Because, the other is all the fields we do not want to be submitted by the user to decide, you can pass

The AutoComplete feature defines additional field writes.
Filert (Filtering of field content) is somewhat similar to I's Judgment $User->data ($data)->filter

(' Strip_tags ')->add (); filters out HTML tags (functions that support callback types can be functions or closures

Custom
The having method is to be queried again from the result of the grouping with the group method.
Cache S
Comment Notes
The Create method creates a data object that is saved in memory and is not actually written to the database until you use the add

Or the Save method is actually written to the database. Add or save is not written to the database, so you can

To change the Create object.

----
Find (read a field) Select (Read field set) GetField (read field value) [Digital update setinc SETDEC]
Delete () [will not be deleted when no conditions are passed in, similar to Seve]

When the form map data gets, the automatic processing setting turns on ' Read_data_map ' =>true
You can also use PARSEFIELDSMAP for format conversions
Query method
Array ' _logic ' = ' OR ' uses object mode to query StdClass
$map [' B '] =array (' Notlike ', Array ('%thinkphp% ', '%tp '), ' and ');
The EXP expression query (the condition of the EXP query is not treated as a string) all subsequent query conditions can use any

SQL supports syntax, including the use of functions and field names. Query expressions can be used not only for query criteria, but also for numbers.

It is updated.
$data [' score '] = Array (' exp ', ' score+1 ');//user's points plus 1
$User->where (' id=5 ')->save ($data); Save modified data based on conditions

Support for multi-language packs L

*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_12_1
????????????????????????????????????????
Multilevel Controller
Instantiating a controller
Distinct
Tokens (token authentication)
ORM table mapping to class records mapping to Objects
AR mode ActiveRecord a simple command
How to enable support for local session management with prefix

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

http://www.bkjia.com/PHPjc/920432.html www.bkjia.com true http://www.bkjia.com/PHPjc/920432.html techarticle Onthink Study Essays, Onthink essay-------------------------------------(Write Code not lonely _ small generation) with Onthink wrote a website temporarily not online function slightly not complete, completely ...

  • 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.