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 without a template tag system Although there will be 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.
Below The diagram 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.
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 have 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.
Regain the reference to the ViewResourcesConfig object, which Contains configuration parameters.
Set the path to the template source file and compiled template file in the ViewResourcesConfig parameter.
2. Set the label page
The extension of the template source file (may be ".ssp") Is used to compare with the ViewResourcesConfig->tagFlagStr parameter to determine if this page needs to be processed, otherwise the page will be processed as a standard (untag) template file. We can configure the tag file extension in the view-resources element, like 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). Data For example, -4 represents the last 4 characters of the source file name. The default values are .ssp and -4, so if we use a template file name like myPage.ssp, we do not need to set these parameters.
3. Process tags File
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 The processor will not be called. Developers only need to set it to true during development, otherwise it will not be processed. But it should be noted that when the processTags attribute is set to true, the modified tag page will be compiled ( This depends on the compileAll attribute setting). We can define the processTags attribute on the view-resources element, like this:
processTags = "True"
.. .
Note that its default value is false.
4. Compile the template page.
If TagActionDispatcher decides that the template page will be processed, then it will pass control to 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 compile the modified ones Page.
If the compileAll attribute is set to false (the 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 to true, the template tag system will always compile the page (including included pages) regardless of whether the page has been modified since the last request. Developers use 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 Processed by any other regular PHP.MVC template file. TagActionDispatcher retrieves the compiled page (including the containing page) and outputs the page to the user's browser. If the template tag system is not called, TagActionDispatcher will be the requested page Processed as a regular VIEW resource. For example, TagActionDispatcher can be used instead of the standard ActionDispatcher.