Page Layout
In this unit we will see how to use the template tag system to construct a standard template page. For this example we use a simple HTML page layout, please see the picture below:
This page is composed of multiple standard units, just like page designers and developers are familiar with. The main body of this page consists of 3 It consists of units: header, page content body and footer. We will now look at these units and understand how to use the template tag system to implement.
Page Body
The following code unit displays the body:
The Page Body Layout
1
2 "
" 'pageLayoutTable'>
3
;
; 4
'>
' '
1: Page Declaration
The first interesting entry is the page declaration (1) at the top of the page. We declare these variables at the beginning of the page, so these variables will be available in the page below and in the containing page like the header. .
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:
...
3: Header
The header is the next interesting entry (3). Here we use the include directive to insert the header template file Go to the page body. We will take a look at the header in the next sub-unit.
We just used the page to read the header directly, regardless of where the page components are stored. This is a good opportunity to introduce the template tag system Directory settings. By default, the template directory layout looks like this (note 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, like this:
tplDir = "./WEB-INF/tpl-admin"
tplDirC = "./WEB-INF/tpl_admin_C"
...
4: Page content body
This is another containing directive Used to insert template files (4) into the body. Note that the included files are located in the sales subdirectory of the template directory:
"./WEB-INF/tpl/sale/pageContent.ssp"
5: Footer
Another one Contains directives, just like a page header.
Header unit
In this example the header template file ('pageHeader.ssp') is just a simple unit, like this:
getAppTitle(); ?>
The compiled page is stored in In the compiled template directory, as mentioned above, the default compiled template directory is:
'./WEB-INF/tpl_C'
Page content main unit
The page content main template file is a bit complicated. File ('sale /pageContent.ssp') content is displayed as follows:
...1
getValueBean("ITEM_1") @>
getValueBean("PRODUCTS_ARRAY" ) @>
2
3
ue' > class ='productsTable'>
Our Staff at Your Service
...
5
Area Manager: |
|
1: Some more declarations
The extra declarations (1) shown at the top of the page allow us to declare page variables for use below. After the content has been processed, these declarations will After compilation, it is displayed as follows:
getValueBean("ITEM_1"); ?>
...
getValueBean( "PRODUCTS_ARRAY"); ?>
2: Use expressions to display the title of the content unit
Now we use two expressions (2) to display the title of the content unit. Note that we declare these variables as "global" variables on the main page at the top. After processing, the expression will transform these codes, like this:
When the page is displayed to the user's browser In the browser, the title of the content unit looks like this:
Jack's Super Deals for : May 2010.
3: Use expressions to display some data items
Now we can display some actual data (3). In this page content In the main unit we access some product item 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 . .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: ";
AddValueBean saleMonth);
$valueBeans->addValueBean('SALE_TITLE' , $saleTitle);
$valueBeans->addValueBean('DEAL_HEADING' , $dealHeading);
...
we could receive from a database query
//note: The Product Class File WAS Included in Our Local Prepend.php File
$ ITEM1 = New PRODUCT ('Super Duper', $ PRI CE1); ('ITEM_1', $item1);
:...
// Save the Value object
saveValueObject($request, $ $valueBeans); $item1 Now it can be retrieved in the template page:
getValueBean("ITEM_1") @>
We can display the value of the item like this:
4: Display array
We can also use some PHP code directly on our template page. In this detached MVC pattern, we should only go here Write code to manipulate the data provided through the ActionObject and ViewResourcesConfig instances (or perhaps our custom beans). In the content unit above ('sale/pageContent.ssp'), we use a PHP foreach syntax (4 ) to loop through the $products array. We can see in the PhpMVCTabAction class above that the $products array is created and saved in the ActionObject, similar to the $item1 Bean above. In the foreach loop we can use expressions to Display product data:
;/td>
Display the ViewResourcesConfig attribute
Finally, we display the "Area Manager" (5) from the ViewResourcesConfig attribute defined by the view-resources element on our content page:
. ..
className ."/>
But note that in this example we use an object that inherits the ViewResourcesConfig class (MyViewResourcesConfig) to set some custom properties. We define an object that extends the ViewResourcesConfig class, Use the className="MyViewResourcesConfig" attribute 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 properties ("areaManager") , we define this property in the view-resources node:
class MyViewResourcesConfig extends ViewResourcesConfig {
// ----- Properties --------------------- -------------------------------- //
var $areaManager = '';
function getAreaManager() {
return $this->areaManager;
been been Being -- function setAreaManager($areaManager) { :
Note: In a real application the data can be obtained from a relational database.
Footer unit
The footer unit is handled similarly to the header unit discussed above. The footer template file ('tpl/pageFooter.ssp') looks like this:
When the main page (including included pages) is compiled, the expression in the footer is converted to the following:
getCopyright(); ?>
The compiled header page is stored in the compiled template directory. Default The compiled template directory is:
'./WEB-INF/tpl_C'
The above is the content of PHP.MVC's template tag system (4). For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Mac version
God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1
Powerful PHP integrated development environment
