PHP. MVC template tag system (2)

Source: Internet
Author: User

The Php. MVC Tag Action Dispatcher

TagActionDispatcher is a standard implementation of the ActionDispatcher class. It supports accessing basic template tags. the TagActionDispatcher class supports the same ActionObjects set and ViewResourcesConfig attributes as the default ActionDispatcher. the TagActionDispatcher class can be used on systems with or without template tags, although its extra processing may cause minor performance degradation.
The template tag library is a subsystem of the PHP. MVC framework structure. The template tag library works with TagActionDispatcher to support some simple template tags.
The following figure shows PHP. MVC template tag system overview. the process of the template tag system is displayed on the left. on the right is the process of TagActionDispatcher, and how the tag template makes these classes interact.

1. Initialization
When the Controller passes the control to the TagActionDispatcher, some initialization triggers are used to set the ActionObjects and ViewResourcesConfig attributes in order to use our template:
Obtain the $ form, $ errors, and $ data objects from the request. If any of these objects has been created before (for example, in the Action class ), the object will not be visible in the resource template. Otherwise, the object will be set to NULL.
Obtain the reference of the ViewResourcesConfig object again. It contains the configuration parameters.
Set 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 (which may be ". ssp ") is used to compare with the ViewResourcesConfig-> tagFlagStr parameter to determine whether the page needs to be processed. Otherwise, the page will be processed as a standard (unlabeled) template file. we can configure the Tag file extension in the view-resources element, as shown in the following figure:
<View-resources
...
TagFlagStr = ". ssp"
TagFlagCnt = "-4"
...
</View-resources>
TagFlagStr indicates that the tag template source file can be preprocessed, for example, myPage. ssp. this extension triggers tag processing. the tagFlagCnt attribute defines the number of characters ending with the file name, including ". "(xxxYyy. ssp ). for example,-4 represents the last 4 characters in the source file name. the default value is. ssp and-4, so if we use a template file name like myPage. ssp, we do not need to set these parameters.
3. Process tag files
The template tag system determines whether to run the tag processor based on the ViewResourcesConfig-> processTags attribute. if this attribute is true, the template page (and its contained pages) will be processed by the tag processor class, otherwise the tag processor will not be called. developers only need to set it to true in development, and false will not be processed. note that when the processTags attribute is set to true, the modified tab is compiled (this depends on the compileAll attribute setting ). we can define the processTags attribute in the view-resources element, like this:
<View-resources
...
ProcessTags = "True"
...
</View-resources>
Note that its default value is false.
4. Compile the template page.
If TagActionDispatcher decides that the template page will be processed, it will pass control to the template tag system. the template tag system determines whether to compile only modified pages or compile all pages. this behavior is defined using the ViewResourcesConfig-> compileAll attribute. we define the compileAll attribute as follows:
<View-resources
...
CompileAll = "True"
...
</View-resources>
This property is false by default.
5. Compile only modified pages.
If the compileAll attribute is set to false (default), only modified pages are compiled. for example, if the requested page has been modified since the last request, the page will be compiled.
6. compile all pages.
If the compileAll attribute is set to true, the template tag system always compiles pages (including included pages) regardless of whether the page has been modified since the previous request. developers can use this option in development to ensure that all pages are processed.
7. process VIEW resources.
After the template page is processed, control returns to TagActionDispatcher. the requested VIEW Resource (Template File) will be used by any other regular PHP. process the MVC template file. tagActionDispatcher re-obtains the compiled page (including the contained page) and outputs the page to the user's browser. if the template tag system is not called, TagActionDispatcher processes the requested page as a regular VIEW resource. for example, TagActionDispatcher can be used to replace standard ActionDispatcher.

Related Article

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.