PHP.MVC template tag system (4)
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,
