Page layout & nbsp; in this unit, we will see how to use the template tag system to construct a standard template page. In this example, we use a simple HTML page layout. please refer to: & nbsp; This page consists of multiple standard units, just as page designers and developers are familiar. the body of this page consists of three contained units: header, content body, and footer. now let's take a look at these units and learn how to use the template tag system to implement them. page layout
In this unit, we will see how to use the template tag system to construct a standard template page. In this example, we use a simple HTML page layout. please refer:
This page consists of multiple standard units, just as page designers and developers are familiar. the body of this page consists of three contained units: header, content body, and footer. now let's take a look at these units and learn how to use the template tag system to implement them.
Page Subject
The following code unit displays the subject:
The Page Body Layout
1
<@ SaleMonth = data. getValueBean ('sale _ month') @>
<@ SaleTitle = data. getValueBean ('sale _ title') @>
<@ DealHeading = data. getValueBean ('dest_heading ') @>
<@ SalesAreaID = "Central District" @>
<Br/> 2 <@ = viewConfig. getAppTitle @> <br/>
3 <@ include 'pageheader. SS' @> |
4 <@ include 'sale/pageContent. SS' @> |
5 <@ include 'pagefooter. SS' @> |
1: page declaration
The first interesting entry is the page declaration at the top of the page (1 ). we declare these variables on the page, so these variables can be used on the following page and include pages like the header.
2: Page title
Next we will use the expression to initialize the page title (2). This value can be obtained from the view-resources element in the configuration file using ViewResourcesConfig-> getAppTitle:
AppTitle = "Flash Jacks 'sleek Tab Site"
...
3: Header
The header is the next interesting entry (3). here we use the include command to insert the header template file to the page body. we will take a look at the header in the next subunit.
We only use the page to directly read the header, no matter where the page components are stored. this is a good opportunity to introduce the directory settings of the template tag system. by default, the template directory layout is as follows (note that these paths are relative to our application ):
The Default phpMVC_Tags Template Directory Layout Paths (relative)
The Template Files './WEB-INF/tpl'
The Compiled Template Files './WEB-INF/tpl_C'
If necessary, we can redefine them at the view-resources node of the configuration file, as shown in the following figure:
...
TplDir = "./WEB-INF/tpl-admin"
TplDirC = "./WEB-INF/tpl_admin_C"
...
4: page content subject
This is another include command used to insert the template file (4) to the subject. Note that the included file is located in the sales subdirectory of the template directory:
"./WEB-INF/tpl/sale/pageContent. ssp"
5: footer
It is also a containing command, just like the header.
Header unit
In this example, the header template file ('pageheader. SS') is just a simple unit, like this:
<@ = ViewConfig. getAppTitle @>
When the subject page (including the contained page) is compiled, the header expression is converted to the following:
GetAppTitle () ;?>
The compiled page is stored in the compiling Template directory. as mentioned above, the default compiling Template directory is:
'./WEB-INF/tpl_C'
Page content entity unit
The page content subject template file is a bit complex. the content of the file ('sale/pageContent. SS') is shown as follows:
...
1
<@ Item1 = data-> getValueBean ("ITEM_1") @>
<@ Products = data-> getValueBean ("PRODUCTS_ARRAY") @>
2
<@ = DealHeading @> <@ = saleMonth @>
3
Clearance deals
<@ = Item1.getName @> |
<@ = Item1.getCost @> |
4
Todays specials
<@ = Item. getName @> |
<@ = Item. getCost @> |
Our Staff at Your Service
...
5
Area Manager: |
<@ = ViewConfig. getAreaManager @> |
...
1: more statements
The additional declaration shown on the top of the page (1) allows us to declare the page variables so that they can be used below. after the content is processed, these statements will be displayed as follows after compilation:
GetValueBean ("ITEM_1");?>
...
GetValueBean ("PRODUCTS_ARRAY");?>
2: Use expressions to display the content unit title
Now we use two expressions (2) to display the title of the content unit. note that we declare these variables as "global" variables at the top of the home page. after processing, the expression will convert the code like this:
When the page is displayed in the user's browser, the title of the content unit looks like this:
Jack's Super Deals for: May 2010.
3: Use expressions to display some data entries
Now we can display some actual data (3 ). on this page, we access the product entry data in the ActionObject of the PhpMVCTabAction class. A simplified PhpMVCTabAction class is shown below:
Class PhpMVCTabAction extends Action {
...
Function execute ($ mapping, $ form, & $ request, & $ response ){
// Our value bean container
$ ValueBeans = & new ValueBeans ();
// Define some strings we need on our View template page
// These cocould be defined globally in the phpmvc-config.xml file.
// See: ExtendedController example.
$ AppTitle = "Flash Jack's Include Page ";
$ SaleMonth = "May 2010 ";
$ SaleTitle = "Flash Jack's Super Sale ";
$ DealHeading = "Jack's Super Deals :";
...
// Save the string variables to our Value object
$ ValueBeans-> addValueBean ('app _ title', $ appTitle );
$ ValueBeans-> addValueBean ('sale _ month', $ saleMonth );
$ ValueBeans-> addValueBean ('sale _ title', $ saleTitle );
$ ValueBeans-> addValueBean ('dest_heading ', $ dealHeading );
...
// Some float values we cocould receive from a database query
// Note: The prices are formatted in the Products class constructor.
// Eg: "$ n, nnn. nn"
$ Price1 = 125.00;
...
// Setup some clearance deals (inpidual object instances ):
// Note: The Product class file was encoded in our local prepend. php file
$ Item1 = new Product ('Super Duper ', $ price1 );
...
$ ValueBeans-> addValueBean ('item _ 1', $ item1 );
...
// Todays specials (array of object instances)
$ Products = array ();
$ Products [] = new Product ('gooses Bridle ', $ price3 );
...
$ ValueBeans-> addValueBean ('products _ array', $ PRODUCTS );
// Our staff
$ Staff1 = & new Staff ('Bruce ', 'sales', 'Karate ');
...
$ ValueBeans-> addValueBean ('staff _ 1', $ staff1 );
...
// Save the Value object
$ This-> saveValueObject ($ request, $ valueBeans );
In the code above, we can see that the valueBeans entry. Bean data entry created and saved as ActionObject can be re-obtained on the template page:
<@ Item1 = data-> getValueBean ("ITEM_1") @>
We can display the entry value as follows:
<@ = Item1.getName @>
...
<@ = Item1.getCost @>
4: Display arrays
We can also directly use some PHP code on our template page. in this separated MVC mode, we should write code here to manipulate the data provided by the ActionObject and ViewResourcesConfig instances (which may be available for our custom beans. the preceding content unit ('sale/pageContent. in SSPs '), we use a PHP foreach syntax (4) to read the $ products array cyclically. in the above PhpMVCTabAction class, we can see that the $ products array is created and saved in ActionObject, which is similar to the $ item1 Bean above. in the foreach loop, we can use expressions to display product data:
<@ = Item. getName @>
<@ = Item. getCost @>
5: Display ViewResourcesConfig attributes
Finally, we will display "Area Manager" (5) on our content page from the ViewResourcesConfig attribute defined by the view-resources element:
AppTitle = "Flash Jacks 'sleek Tab Site"
...
ClassName = "MyViewResourcesConfig">
However, in this example, we use an object that inherits the ViewResourcesConfig class (MyViewResourcesConfig) to set some custom attributes. we define an object that extends the ViewResourcesConfig class. in the configuration file, use the className = "MyViewResourcesConfig" attribute, and the MyViewResourcesConfig class is defined in the file "MyViewResourcesConfig. php. myViewResourcesConfig class (classes/MyViewResourcesConfig. php) implements the setter/getter method to process custom attributes ("areaManager"). This attribute is defined in the view-resources node:
Class MyViewResourcesConfig extends ViewResourcesConfig {
// ----- Properties -----------------------------------------------------//
Var $ areaManager = '';
Function getAreaManager (){
Return $ this-> areaManager;
}
Function setAreaManager ($ areaManager ){
$ This-> areaManager = $ areaManager;
}
Now we can use expressions to implement "Area Manager" on our page:
<@ = ViewConfig. getAreaManager @>
Note: data in real applications can be obtained from relational databases.
Footer unit
The footer unit is similar to the header unit discussed above. The footer template file ('tpl/pageFooter. SS') is like this:
<@ = ViewConfig. getCopyright @>
When the subject page (including the contained page) is compiled, the expression in the footer is converted to the following:
GetCopyright ();?>
The compiled header page is stored in the compiling Template directory. the default compiling Template directory is:
'./WEB-INF/tpl_C'