PHP.MVC template tag system (4)_PHP tutorial
Jul 21, 2016 pm 04:12 PM頁面布局
??? 在這個單元中我們將看到如何使用模板標簽系統(tǒng)構造一個標準的模板頁面。這個例子我們使用了一個簡單的HTML頁面布局,請看下圖:
??? 這個頁面有多個標準單元組成,就像頁面設計者和開發(fā)者熟悉的那樣.這個頁面的主體由3個包含的單元組成:頁眉,頁內容主體和頁腳.我們現(xiàn)在就看看這些單元并且了解如何使用模板標簽系統(tǒng)來實現(xiàn).
頁主體
??? 下面的代碼單元顯示的是主體:
The Page Body Layout?
1
<@ saleMonth = data.getValueBean('SALE_MONTH') @>
<@ saleTitle = data.getValueBean('SALE_TITLE') @>
<@ dealHeading = data.getValueBean('DEAL_HEADING') @>
<@ salesAreaID = "Central District" @>
??
??
2???? <@ =viewConfig.getAppTitle @>
??
???????? ???????? 3??????? <@ include 'pageHeader.ssp' @> ????? |
???????? 4??????? <@ include 'sale/pageContent.ssp' @> ????? |
???????? 5??????? <@ include 'pageFooter.ssp' @> ????? |
1:頁聲明
??? 第一個有趣的條目是頁頂部的頁聲明(1).我們在頁面開始聲明了這些變量,因此這些變量將能在下面的頁面和像頁眉那樣的包含頁所使用.
2:頁標題
??? 下一步我們使用表達式來初始化頁面標題(2).這個值能夠從配置文件中view-resources元素利用ViewResourcesConfig->getAppTitle來得到:
...
3:頁眉
??? 頁眉是下一個有趣的條目(3).在這里我們使用包含指令來插入頁眉模板文件到頁主體中.我們將在下一個子單元中來看一看頁眉.
??? 我們僅僅使用了頁面直接去讀取頁眉,不論頁的組件存儲在哪里.這是一個好機會來介紹模板標簽系統(tǒng)的目錄設置.默認情況下,模板目錄布局如下所示(注意這些路徑相對于我們的應用程序):
The Default PhpMVC_Tags Template Directory Layout Paths (relative)?
The Template Files? './WEB-INF/tpl'?
The Compiled Template Files? './WEB-INF/tpl_C'?
??? 如果需要的話我們可以在配置文件的view-resources結點來重新定義他們,就像這樣:
tplDir = "./WEB-INF/tpl-admin"
tplDirC = "./WEB-INF/tpl_admin_C"
...
4:頁內容主體
??? 這是另外一個包含指令被用來插入模板文件(4)到主體中.注意包含的文件位于模板目錄的sales子目錄中:
"./WEB-INF/tpl/sale/pageContent.ssp"
5:頁腳
??? 又是一個包含指令,就像頁眉一樣.
頁眉單元
??? 在這個例子中頁眉模板文件('pageHeader.ssp')只是一個簡單的單元,就像這樣:
?? <@ =viewConfig.getAppTitle @>
??? 當主體頁面(包括包含的頁面)被編譯的時候,頁眉的表達式被轉換成下面這樣:
?? getAppTitle(); ?>
??? 被編譯的頁面被存儲在編譯模板目錄中,就像上面所說的,默認的編譯模板目錄是:
'./WEB-INF/tpl_C'
頁內容主體單元
??? 頁內容主體模板文件有一點復雜.文件('sale/pageContent.ssp')內容顯示如下:
...
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:一些更多的聲明
??? 在頁面頂部所顯示的額外聲明(1)能讓我們聲明頁變量以便下面能夠使用.在內容被處理之后,這些聲明將在編譯后像下面這樣顯示:
getValueBean("ITEM_1"); ?>
...
getValueBean("PRODUCTS_ARRAY"); ?>
2:使用表達式來顯示內容單元標題
??? 現(xiàn)在我們使用兩個表達式(2)來顯示內容單元的標題.注意我們聲明這些變量是"全局"變量在主頁面的頂部.處理完后,表達式將轉換這些代碼,就像這樣:
??? 當頁面被顯示到用戶的瀏覽器中,內容單元的標題看起來就像這樣:
Jack's Super Deals for : May 2010.
3:使用表達式來顯示一些數(shù)據(jù)條目
??? 現(xiàn)在我們能顯示一些實際的數(shù)據(jù)(3).在這個頁內容主體單元中我們訪問一些在PhpMVCTabAction類的ActionObject中的產(chǎn)品條目數(shù)據(jù).一個簡化版的PhpMVCTabAction類在下面展示:
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 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 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 are formatted in the Products class constructor.
????? // Eg: "$ n,nnn.nn"
????? $price1 =? 125.00;
????? ...
????? // Setup some clearance deals (individual object instances):
????? // Note: The Product class file was included 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);
??? 在上面的代碼中,我們能看到$item1被創(chuàng)建并被保存成ActionObject的valueBeans條目.Bean數(shù)據(jù)條目現(xiàn)在能在模板頁面中被重新獲得:
<@ item1=data->getValueBean("ITEM_1") @>
??? 我們可以像下面那樣顯示條目的值:
<@ =item1.getName @>
...
<@ =item1.getCost @>
4:顯示數(shù)組
??? 我們也可以直接使用一些PHP代碼在我們的模板頁上.在這個分離的MVC模式中,我們應該僅在這里編寫代碼去操縱這些通過ActionObject和ViewResourcesConfig實例(可能我們的自定義Bean也可以)提供的數(shù)據(jù).在上面的也內容單元('sale/pageContent.ssp')中,我們使用一個PHP的foreach語法(4)來循環(huán)讀取$products數(shù)組.我們能在上面的PhpMVCTabAction類中看到$products數(shù)組被創(chuàng)建并被保存在ActionObject中,就和上面的$item1 Bean相似.在foreach循環(huán)中我們能使用表達式來顯示產(chǎn)品數(shù)據(jù):
??
?????
???????? <@ =item.getName @>
?????
?????
???????? <@ =item.getCost @>
??????
??
5:顯示ViewResourcesConfig屬性
??? 最后我們從view-resources元素所定義的ViewResourcesConfig屬性來顯示"Area Manager"(5)在我們的內容頁:
...
className = "MyViewResourcesConfig">
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????>
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, in the configuration file Use the className="MyViewResourcesConfig" attribute, and the MyViewResourcesConfig class is defined in the file "MyViewResourcesConfig.php". The MyViewResourcesConfig class (classes/MyViewResourcesConfig.php) implements the setter/getter method to handle the custom attribute ("areaManager"). This attribute We define it in the view-resources node:
class MyViewResourcesConfig extends ViewResourcesConfig {
// ----- Properties --------------------------------------- ------------- //
var $areaManager = '';
function getAreaManager() {
return $this->areaManager; }
function setAreaManager($areaManager) {
}
We can now use expressions to implement "Area Manager" on our page:
<@ =viewConfig.getAreaManager @>
Note: In real applications, 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:
<@ =viewConfig.getCopyright @>
When the main page (including included pages) is compiled, the expression in the footer is converted into the following:
getCopyright(); ?>
The compiled header page is stored in the compiled template directory. The default compiled template directory is:
'./WEB-INF/tpl_C'
http://www.bkjia.com/PHPjc/313701.html

Hot AI Tools

Undress AI Tool
Undress images for free

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

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

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

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

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Xiaomi car software provides remote car control functions, allowing users to remotely control the vehicle through mobile phones or computers, such as opening and closing the vehicle's doors and windows, starting the engine, controlling the vehicle's air conditioner and audio, etc. The following is the use and content of this software, let's learn about it together . Comprehensive list of Xiaomi Auto app functions and usage methods 1. The Xiaomi Auto app was launched on the Apple AppStore on March 25, and can now be downloaded from the app store on Android phones; Car purchase: Learn about the core highlights and technical parameters of Xiaomi Auto, and make an appointment for a test drive. Configure and order your Xiaomi car, and support online processing of car pickup to-do items. 3. Community: Understand Xiaomi Auto brand information, exchange car experience, and share wonderful car life; 4. Car control: The mobile phone is the remote control, remote control, real-time security, easy
