Page layout
In this module we will see how to construct a standard template page using the template tagging system. In this example we use a simple HTML page layout, see:
This page is composed of several standard units, just as the page designer and developer are familiar with. The body of this page consists of 3 contained cells: the header, the page content body, and the footer. Let's take a look at these units and learn how to use the template labeling system.
Page body
The following code unit shows the body:
The Page Body Layout
1
<@ salemonth = Data.getvaluebean (' sale_month ') @>
<@ saletitle = Data.getvaluebean (' sale_title ') @>
<@ dealheading = Data.getvaluebean (' deal_heading ') @>
<@ salesareaid = "Central District" @>
<br>2 <@ =viewconfig.getapptitle @><br>
3 <@ include ' PAGEHEADER.SSP ' @>
|
4 <@ include ' SALE/PAGECONTENT.SSP ' @>
|
5 <@ include ' PAGEFOOTER.SSP ' @>
|
1: Page declaration
The first interesting entry is the page declaration at the top of the page (1). We declare these variables at the beginning of the page, so these variables will be used in the following pages and include pages like headers.
2: page title
Next we use an 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 directive to insert a header template file into the body of the page. We'll look at the header in the next sub-unit.
We just use the page to read the header directly, regardless of where the page's components are stored. This is a good opportunity to introduce the directory settings for the template label system. By default, the template directory layout looks like this (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 in the View-resources node of the configuration file, just like this:
<>
...
Tpldir = "./web-inf/tpl-admin"
Tpldirc = "./web-inf/tpl_admin_c"
...
4: Page content body
This is another one that contains directives that are used to insert template files (4) into the body. Note the included files are located in the sales subdirectory of the template directory:
"./web-inf/tpl/sale/pagecontent.ssp"
5: Footer
Another containing instruction, just like a header.
Header Unit
In this example, the header template file (' PAGEHEADER.SSP ') is just a simple unit, just like this:
<@ =viewconfig.getapptitle @>
When the main page (including the included page) is compiled, the header expression is converted to the following:
Getapptitle ();?>
The compiled page is stored in the compiled template directory, as stated above, and the default compilation template directory is:
'./web-inf/tpl_c '
Page Content Body Unit
The page content body template file is a bit more complex. The file (' SALE/PAGECONTENT.SSP ') content is displayed 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: Some more statements
The additional declaration shown at the top of the page (1) allows us to declare page variables so that they can be used below. After the content is processed, these declarations will appear as follows after compilation:
Getvaluebean ("Item_1");?>
...
Getvaluebean ("Products_array");?>
2: Use an expression to display a content cell title
Now we use two expressions (2) to display the title of the content cell. Note We declare that these variables are "global" variables at the top of the main page. After processing, the expression transforms 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 an expression to display some data entries
Now we can show some actual data (3). In this page content body unit We access some of the product entry data in the Actionobject of the Phpmvctabaction class. A simplified version of the 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 could is 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 for:";
...
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 (' deal_heading ', $dealHeading);
...
Some float values we could receive from a database query
Note:the prices is formatted in the Products class constructor.
Eg: "$ n,nnn.nn"
$price 1 = 125.00;
...
Setup Some clearance deals (individual object instances):
Note:the Product class file is included in our local prepend.php file
$item 1 = new Product (' Super duper ', $price 1);
...
$valueBeans->addvaluebean (' item_1 ', $item 1);
...
Todays Specials (Array of object instances)
$products = Array ();
$products [] = new Product (' gooses bridle ', $price 3);
...
$valueBeans->addvaluebean (' Products_array ', $products);
Our Staff
$staff 1 =& new staff (' Bruce ', ' Sales ', ' Karate ');
...
$valueBeans->addvaluebean (' staff_1 ', $staff 1);
...
Save the Value Object
$this->savevalueobject ($request, $valueBeans);
In the above code, we can see the Valuebeans entries that $item1 was created and saved as actionobject. The bean data entry can now be re-acquired in the template page:
<@ Item1=data->getvaluebean ("item_1") @>
We can display the value of the entry as follows:
<@ =item1.getname @>
...
<@ =item1.getcost @>
4: Display Array
We can also use some PHP code directly on our template page. In this isolated MVC pattern, we should only write code here to manipulate these through actionobject and Viewresourcesconfig instances (maybe our custom bean can also) The data provided. In the above also the content unit (' SALE/PAGECONTENT.SSP '), we use a PHP foreach Syntax (4) to iterate through the $products array. We can see the $ in the Phpmvctabaction class above The products array is created and saved in Actionobject, similar to the $item1 bean above. In a Foreach loop we can use expressions to display product data:
<@ =item.getname @>
<@ =item.getcost @>
5: Show Viewresourcesconfig Property
Finally we show "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" >
But notice in this example that we used an object that inherits the Viewresourcesconfig class (Myviewresourcesconfig) to set some custom properties. We define an object that extends the Viewresourcesconfig class. The classname= "Myviewresourcesconfig" attribute is used in the configuration file, and the Myviewresourcesconfig class is defined in the file "myviewresourcesconfig.php". The Myviewresourcesconfig Class (classes/myviewresourcesconfig.php) implements the Setter/getter method to handle custom attributes ("Areamanager"), This property 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;
}
We can now implement "area Manager" on our page using an expression:
<@ =viewconfig.getareamanager @>
Note: Data can be obtained from a relational database in a real-world application.
Footer Unit
The footer unit is similar to the processing of the header unit discussed above. The Footer template file (' Tpl/pagefooter.ssp ') is like this:
<@ =viewconfig.getcopyright @>
When the principal page (including the included page) is compiled, the expression in the footer is converted to the following:
Getcopyright ();?>
The compiled header page is stored in the compiled template directory. The default compilation template directory is:
'./web-inf/tpl_c '
http://www.bkjia.com/PHPjc/313701.html www.bkjia.com true http://www.bkjia.com/PHPjc/313701.html techarticle page layout In this unit we will see how to construct a standard template page using the template tagging system. In this example we use a simple HTML page layout, please see ...