Speaking of the single-entry PHP mode, I soon came up with some PHP frameworks, such as zend, thinkphp, qeephp, and cakephp. They all adopt a unified portal based on different needs, this design mode has obvious advantages, for example, the front-end portal or other operation permission portal. Permission control, url rewriting, and MVC clear directory structure. These are the conveniences brought about by the single portal mode. Of course, this will also bring about doubts about the execution efficiency.
The single-entry mode combines the OO features.
<? Phpclass A {private static $ tag = null; private function _ construct () {} static function getObject () {if (null = self ::$ tag) {self :: $ tag = new A ();} return self: $ tag; }}$ object1 = A: getObject (); $ object2 = A: getObject (); if ($ object1 ===$ object2) {echo "same object";} else {echo "different objects ";}$ Tag indicates whether the class is instantiated. If $ tag is empty, the current class is instantiated and assigned to $ tag. If not empty, the static attribute pointing to the instance is returned.
Continuing knowledge extension... factory Model
The factory mode is used by a factory class to determine which product class instance to create based on the input parameters. The factory model is not very practical in small projects. However, this encoding method is worth learning and using, and is applicable to projects of any size. Combined with the MVC structure, you can think of some of the current framework structures.
The following is a comparison of the five frameworks written in Xiaoyao Bingxin. Some of the content is objective.
Http://www.demonitech.com/index.php/archives/100
Single portal mode (taking thinkphp as an example)
<? Php // define the ThinkPHP framework PATH define ('Think _ path ','. /ThinkPHP/'); // define the project NAME and PATH define ('app _ name', 'myapp'); define ('app _ path ','. '); // load the framework entry file require (THINK_PATH. "/ThinkPHP. php "); // instantiate a website application instance App: run ();Thinkphp's explanation of a single entry
"A single portal usually refers to a project or application with a unified (but not necessarily unique) Portal file. That is to say, all function operations of the project are performed through this portal file, in addition, the entry file is usually executed in the first step.
The advantage of a single portal is that the project is relatively standardized as a whole, because the same portal usually has the same rules between different operations. In addition, the advantage of a single portal is that the control is more flexible, because the interception is convenient. For example, some permission control and user logon judgment and operations can be handled in a unified manner.
Or some people may worry that all websites will be accessed through an entry file and whether it will put too much pressure on them. In fact, this is a worrying idea ."
Let me see the thinkphp structure.
Process:
Under thinkphp. php,
<? Php $ GLOBALS ['_ inintime'] = microtime (TRUE); if (! Defined ('app _ path') define ('app _ path', dirname ($ _ SERVER ['script _ filename']); if (! Defined ('runtime _ path') define ('runtime _ path', APP_PATH. '/Runtime/'); if (defined ('runtime _ allinone') & is_file (RUNTIME_PATH. '~ Allinone. php') {// load ALLINONE cache directly in allinone mode $ result = require RUNTIME_PATH .'~ Allinone. php '; C ($ result); // automatically set to run mode define ('runtime _ model', true);} else {if (version_compare (PHP_VERSION, '5. 0.0 ',' <') die ('require PHP> 5.0! '); // ThinkPHP system directory definition if (! Defined ('Think _ path') define ('Think _ path', dirname (_ FILE _); if (! Defined ('app _ name') define ('app _ name', basename (dirname ($ _ SERVER ['script _ filename']); if (is_file (RUNTIME_PATH. '~ Runtime. php') {// load the core compilation cache of the framework require RUNTIME_PATH .'~ Runtime. php';} else {// load the compilation function file require THINK_PATH. "/Common/runtime. php"; // generate the core compilation ~ Runtime cache build_runtime () ;}// record file loading time $ GLOBALS ['_ loadtime'] = microtime (TRUE);?>
Check THINK_PATH, APP_NAME, APP_PATH, and RUNTIME_PATH definitions.
Load System definition file compilation cache directory load system core class library load compatible function libraries according to PHP version generate core compilation cache ~ As for runtime. php, there are too many detailed work in the future. Then build the project configuration file and public file .. Next, go to the app, Dispatcher, and GetModule. I skipped many other steps,
Finally, return to the portal.
Summary:
These recently viewed items are then added to all the items that have no connection with each other. The single-piece mode, factory mode, and single-entry mode are summarized in a general sense, I also need to have a deeper understanding. Based on thinkphp, I understand some basic operation procedures of the next framework. Combined with MVC, I think thinkphp is not powerful enough than zend. But it is suitable for cainiao.