PHP. MVC template tag system (1)

Source: Internet
Author: User

PHP. MVC's template tag system (PhpMVC_Tags) now provides three types of tags: including commands, declarations, and expressions.
The include command separates content into many modules, such as the header, footer, or content. the contained page can be HTML or other tag template pages. for example, the following include command can be used to contain a header:
<@ Include 'pageheader. ss' @>
The Declaration allows us to declare a page-level variable in the template, or even other include pages. A declaration looks like the following code:
<@ SalesAreaID = "Central District" @>
Expression tags allow us to execute expressions on the template page. the expression result is included in the template page. the following expression is used to display a simple string (salesAreaID). You can also retrieve the attributes of the Framework configuration class:
<@ = SalesAreaID @>
<@ = ViewConfig. getAreaManager @>
PHP. MVC beta 0.4.0 introduces a new configuration class called ViewResourcesConfig. this class can be used to define global parameters that can be used in VIEW resources (templates), and also to configure the template tag system, which will be shown below. the view-resources element in the phpmvc-config.xml configuration file is displayed below:
<View-resources
AppTitle = "Flash Jacks 'sleek Tab Site"
Copyright = "Copyright @ 2010 Flash Jack. All rights reserved ."
ContactInfo = "flash.jack@jackshost.com"
ProcessTags = "true"
CompileAll = "true"
ClassName = "MyViewResourcesConfig">

<! -- We can set some properties on our custom ViewResourcesConfig class -->
<Set-property = "areaManager" value = "Joe J. Blogs Esq."/>
</View-resources>
The template page processing system can be controlled by <view-resources> nodes using the template tag system. first, we can define whether the template tag system compiles all template pages or only compiles and modifies the pages. second, we can define whether the template tag system really needs to process the tag page. Processing the tag page is useful when and after the application configuration. the <view-resources> shown in the following unit sets the compileAll and processTags attributes to true (always process the tab and process all tabs ):
<View-resources
...
ProcessTags = "true"
CompileAll = "true"
...
</View-resources>

Action Dispatcher

The ActionDispatcher class above PHP. MVC beta 0.4.0 is used to make FormBean, Errors, Value (business data) and ViewResourcesConfig objects available in our VIEW (Template.
Before checking the template tag system, we should take a quick look at the ActionObjects and ViewResourcesConfig classes when using standard ActionDispatcher.

ActionObjects

ActionDispatcher makes the application VIEW resources of some objects on the template page we use available. Three standard ActionObjects are: FormBean, Errors, and Value (business data) objects.
The following table shows how to use FormBean, Errors, and Value objects in the FormAction and Action classes:
Saving ActionObjects in ActionForm Classes
ActionErrors $ this-> saveErrors ($ request, $ actionErrors)
FormBeans $ this-> saveFormBean ($ request, $ this)
ValueObjects $ this-> saveValueObject ($ request, $ valueObject)

Saving ActionObjects in Action Classes
ActionErrors $ this-> saveErrors ($ request, $ actionErrors)
FormBeans $ this-> saveFormBean ($ request, $ form)
ValueObjects $ this-> saveValueObject ($ request, $ valueObject)

Retrieving ActionObjects in View Resources (Templates)
ActionErrors $ errors-> getItemString ('logon _ username_reqd ')
FormBeans $ form-> username
ValueObjects $ data-> salesNorth

An ActionObject will be initialized to NULL if the object is not created and saved before. to get more information about ActionObjects, see here: http://www.phpmvc.net/docs/guides/guidesIdx.php? Doc = action-objects

View Resources

ActionDispatcher can also expose the ViewResourcesConfig object to our template page. the ViewResourcesConfig object is configured by the <view-resources> element in the phpmvc-config.xml configuration file. if the ViewResourcesConfig object is not configured, a new instance uses the default ViewResourcesConfig class attribute.
The following code shows how to access the ViewResourcesConfig attribute in our HTML header template using the template tag system expression:
<! -- Page Header -->
<Span>
<@ = ViewConfig. getAppTitle @>
</Span>

Configure Action Dispatcher

ActionDispatcher is the default PHP. MVC (version 0.4.0 or later) Dispatcher class. this Action Dispatcher is included in the framework and will be used by default unless we define a class to replace the Dispatcher class. in the next section, we will see how to configure our application to use an alternative class-TagActionDispatcher class.

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.