Home >php教程 >PHP开发 >PHP.MVC template tag system (2)

PHP.MVC template tag system (2)

黄舟
黄舟Original
2016-12-17 10:07:351135browse

The php.MVC Tag Action Dispatcher

TagActionDispatcher is an implementation of the standard ActionDispatcher class that supports access to basic template tags. The TagActionDispatcher class supports the same ActionObjects collection and ViewResourcesConfig properties as the default ActionDispatcher. The TagActionDispatcher class can be used with Or on systems without template tags, although it will cause a small performance drop due to its extra processing.
The template tag library is a subsystem of the PHP.MVC framework. The template tag library works together with TagActionDispatcher to support some simple template tags .
The following chart shows an overview of the PHP.MVC template tag system. The left side shows the program flow of the template tag system. The right side shows the program flow of TagActionDispatcher, and how the tag template enables these classes to interact.

PHP.MVC template tag system (2)

1. Initialization
When the controller passes control to the TagActionDispatcher, some initialization is triggered to set the ActionObjects and ViewResourcesConfig properties in order to use our template:
Retrieve the $form, $errors and $data objects from the request, if any of these objects One has been created before (such as in the Action class), then the object will now not be visible in the resource template, otherwise the object will be set to NULL.
Retrieve a reference to the ViewResourcesConfig object, which contains the configuration parameters.
Set in The path to the template source file and the compiled template file in the ViewResourcesConfig parameter.
2. Set the tag page
The extension of the template source file (possibly ".ssp") is used to compare with the ViewResourcesConfig->tagFlagStr parameter to determine Whether this page needs to be processed, otherwise the page will be processed as a standard (untagged) template file. We can configure the tag file extension in the view-resources element, like this:
...
tagFlagStr = ".ssp"
tagFlagCnt = "-4"
...

  tagFlagStr indicates that the tag template source file can be preprocessed, such as: myPage.ssp. This extension triggers tag processing. The attribute tagFlagCnt defines the number of characters at the end of the file name, including "." (xxxYyy.ssp). According to an example, -4 represents the last 4 characters of the source file name. The default values ​​are .ssp and -4, so if we use a The template file name is like myPage.ssp, we do not need to set these parameters.
3. Process tag files
The template tag system decides whether to run the tag processor based on the ViewResourcesConfig->PRocessTags attribute. If this attribute is true, the template page ( and the pages it contains) will be processed by the tag processor class, otherwise the tag processor will not be called. Developers only need to set it to true during development, otherwise it will not be processed. But please note Modified tags will only be compiled when the processTags attribute is set to true (this depends on the compileAll attribute setting). We can define the processTags attribute on the view-resources element, like this:
.. .
processtags = "true"
...
& lt;/view-resources & gt;
Note, its default value is false .
4.
If tagactionDispatcher decides that the template page will be processed, then it will pass it to it. Control is given to the template tag system. Now the template tag system will decide whether to compile only modified pages, or compile all pages. This behavior is defined using the ViewResourcesConfig->compileAll attribute. We define the compileAll attribute like this:
...
compileAll = "True"
...
This attribute defaults to false.
5. Only the modified pages will be compiled.
If the compileAll attribute is set to false (default value ), then only modified pages will be compiled. For example, if the requested page has been modified since the last time it was requested, this page will be compiled.
6. Compile all pages.
If the compileAll attribute is set If true, the template tag system will always compile pages (including included pages) regardless of whether the page has been modified since the last request. Developers using this option during development can ensure that all pages are processed.
7. Process VIEW resources.
After processing the template page, control returns to TagActionDispatcher. The requested VIEW resource (template file) will be processed by any other regular PHP.MVC template file. TagActionDispatcher regains the compiled page (including included page) and output the page to the user's browser. If the template tag system is not called, TagActionDispatcher will process the requested page as a regular VIEW resource. For example, TagActionDispatcher can be used to replace the standard ActionDispatcher.

Above That’s the content. For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!


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