">

Onthink study essays

WBOY
Release: 2016-08-08 09:33:07
Original
1133 people have browsed it

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

I wrote a website using Onthink. It has not been launched yet. It has some incomplete functions. It has not exerted its power and expansion at all, and it is slightly 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. . .

Day 1: Complete the preface, basics, configuration, architecture, and routing reading of the manual.

Complete the controller model reading on the second day About the appendix reading

The following is the reading transcript

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

use indicates what namespace is introduced for direct reference
The naming method of the function uses lowercase letters and underscores
The naming of the method uses lowercase letters and underscores The underscore represents (general private method)
A function or method starting with a double underscore As a magic method __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;
Conventional configuration application configuration mode configuration debugging configuration status configuration module configuration
Conventional configuration ThinkPHP/Conf/convention.php application configuration is an expansion based on conventional configuration
Application/Common/Conf/config.php is a common configuration file that will be loaded before calling all modules
The optional mode configuration is added in the application configuration folder The file config_application name.php that is run only when running this mode
When debugging mode is turned on, ThinkPHP/Conf/debug.php and the application debugging configuration file Application under the
status configuration are manually separated
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 underlines C method can read 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 applications Entry file)/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 After defining the Application, there is no need to load the Application
3.2.2 The modules and controllers written in the entry file can be automatically generated by default. If you want to generate more controllers, use the BUILD_CONTROLLER_LIST constant
// Bind the Admin module to the current entry file
define('BIND_MODULE','Admin');
define('BUILD_CONTROLLER_LIST ',' Index, User, Menu ');
The method of calling the ThinkBulid class manually to generate the model class ThinkBuild :: Buildmodel
(' admin ',' role '); Used to be called by other modules or not accessible), the default configuration
prohibits access to the Common module and Runtime module (the Runtime directory is the default runtime directory), we can add other
list of prohibited access modules:
'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'                                                                                                                                                                                                                                                                          Single module design is to turn off multi-module access MULTI_MODOULE=> 'm'] = 'Home';
define('APP_PATH','./Application/');require './ThinkPHP/ThinkPHP.php';
After binding http://serverName/index.php/Home /Index/index becomes                                                                                                                                                                                                                                                   ​ , etc. Different model layers create Model, Logic, sercive
When calling, it is very convenient to use the D method to call D('User','Logic');//instantiate UserLogic D('User') is instantiated
UserModel.
Change the system's default view layer DEFAULT_V_LAYER=>'Mobile'; use the T function to obtain templates for non-default view layer directories.
The core controller of the Controller layer is completed in the App class inside the system
Event/UserEvent//It is used for user event response operations. Controller is responsible for external responses. Event is responsible for internal event responses, and can only be used in Internal call A('User','Event');
CBD model
Core(core)+Behavior(behavior)+Driver(driver)
Driver(driver)
3.2 has further strengthened the driver design in the architectural design, replacing Extended the previous engine and mode, and improved the behavior design
The design makes the overall framework more flexible, and because the driver-oriented 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 the support for cloud platforms can Easier to implement.​
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 the position of these behaviors as tags (bits), which can also be used as hooks. When the application runs to this tag, it will be intercepted In this way, related behaviors are uniformly executed, similar to the concept of "aspect" in AOP programming. Binding related behaviors to a certain tag becomes an AOP-like programming idea.
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');
Behavior definition is required. 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's behavior definition file.
     return array(       'Tag name 1'=>array('Behavior name 1',''Behavior name 2',...),      'Tag name                                                                                                                                                                      return array(                                               . Name 2',...), );
Version 3.2.1 or above allows you 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 the efficiency of class libraries mapping multiple root namespaces ThinkThink::addMap($map); $map=array();
Manually Third-party class library import import method imports any class library.
Built-in caching mechanism and running lite files Features of the new version Generate static entry files at runtime.
Application mode Application mode is to add automatic recognition area
Project compilation application compilation cache (cache for first run) - 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
// Enable routing 'URL_ROUTER_ON' => true, 3.2 routing is for modules, so the module name It cannot be routed. The definition of routing is usually in the module configuration file.
Route expression => Routing address and incoming parameters Array('Routing expression', 'Routing address', 'Incoming parameters')
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's keywords, we can set The suffix method
solve'ACTION_SUFFIX'=> 'Action', // The operation method suffix
multi-level controller is to group the controllers
If the instantiated controller is internal, it will be automatically instantiated when using url address resolution If it is called across controllers, instantiate it and call it using shortcut method A (if it is multi-level, use the second parameter of A). You can instantiate the method when instantiating it. Pre- and post-operations (only useful for controllers)
The common ones are _before_index pre-method_after_index post-method If no pre-post method is defined, the real template output may only be the current operation. Pre- and post-operations generally have no output. If the call error operation is successful, there will be no post-operation.
The controller can also bind parameter rules and action parameter binding (variable names can be bound to implement routing functions)
Pseudo-static
URL_HTML_SUFFIX=〉'' The static suffix is ​​recorded to the constant __EXT__ (the current suffix can be obtained)
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 accessing the controller is not case sensitive, 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 for dynamic generation of URLs , which can 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@domain name]?Parameter 1=Value 1& Parameter 2=value 2...
ajax returns ajaxReturn
The data returned by the variable array can be processed by JSON, JSONP, XML and EVAL. The method can be configured to return DEFAULT_AJAX_RETURN. eval can output $data data
JSON and JSONP Although there is only one letter difference, 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 the information.
Jump and redirect
$this->success(prompt information, address, seconds)
----==--=-=
Input variables
You can obtain and filter variables through the I function
I( 'Variable type. Variable name', ['Default value'], ['Filter method'], ['Additional data source'])
The I function comes with DEFAULT_FILTER and the default is htmlspecialchars (Filtering of variables)
Judgment request Type (request type)
is_XXX If it is custom AJAX, you need to add a hidden field to tell the background that it was submitted by ajax. If it is jquery
it is not needed. It can be configured through VAR_AJAX_SUBMI
Empty operation
Automatically call _empty (implementing error pages and some url optimization)
The empty controller system tries to determine the EmptyController
The operation is bound to the class ACTION_BIND_CLASS=〉'true' is more detailed and cannot be omitted
Before The postfix operation needs to be defined in advance
-=-=-=-=-=-=-=-=-=-=-=-
Model Case and conversion
Direct instantiation of the model class generally inherits the model class model Generally there are 3 values: model name data table prefix number
Database connection information
  If you want to write native sql code, you only need to instantiate empty M();
D (instantiation operation of data model)
Parameters of the method It is the name of the model, and is consistent with the uppercase and lowercase definition of the model class.
When the class does not exist, the D function will try to instantiate the public module, and can also be used across modules
M (just perform basic operations on the data table CURD operation) does not require loading specific model classes, so the performance is higher.
Does not support its own business logic
During the instantiation process, we often use the D method and the M method. The difference between these two methods is the M method. Instantiating the model does not require the user to define a model class for each data table. If the D method does not find the defined model class, the M
method will be automatically used.
The field cache includes the field information in the field. You can turn off the automatic caching of fields 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 the call All fields field
(true).
Use table() to switch data tables; When connecting to the database, you can add a label to the connection
System default rules, you must use the model execute write operation query read operation
continuous operation (chain operation)
where can be used in conjunction with where
The data method is for writing to the database and can also be used for updating (save) to determine whether there is a primary key. The object can be a number
group, object or string. Read operations are possible.
field gets the field, and the fields excluded are filed(array('user_id','content'),true); which are fields other than user_id and
content. Used for writing (security control) and does not allow other writing $model->field('name')-
>create(); means that the only legal fields in the form are the name field, no matter what the user passes Means changed or added browser
The submission fields will be directly blocked. 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.
 filert (filtering of field content) is somewhat similar to I’s judgment $User->data($data)->filter                                    ('strip_tags')->add(); Filter out HTML tags (supports callback type functions It can be a function or a closure
Definition)
The having method is to cooperate with the group method to query again from the grouped results.
Cache Sm Comment Note
The data object created by the Create method is that it is stored in the memory, and it is not actually written into the database until the ADD
or Save method is really written into the database. It is written to the database after add or save, so the create object can be changed before there is any change.

----
find (read a field) select (read the field set) getField (read the field value )[Number update setInc setDec]
delete() [It will not be deleted when no conditions are passed in, similar to seve]
When the form mapping data is obtained, the automatic processing setting is turned on 'READ_DATA_MAP'=>true
You can also use parseFieldsMap to convert the format
Query method
Array'_logic'='OR' Use object mode to query stdClass
$map['b'] =array('notlike',array('%thinkphp%', '%tp'),'AND');
exp expression query (exp query conditions will not be treated as strings) All subsequent query conditions can use any syntax supported by
sql, including the use of functions and field names. Query expressions can be used not only for query conditions, but also for numbers.
As 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

Instancing 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 with prefix Support

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

The above introduces the Onthink learning essay, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
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