PHP.MVC template tag system (4)_PHP tutorial
Jul 21, 2016 pm 04:12 PM頁(yè)面布局
??? 在這個(gè)單元中我們將看到如何使用模板標(biāo)簽系統(tǒng)構(gòu)造一個(gè)標(biāo)準(zhǔn)的模板頁(yè)面。這個(gè)例子我們使用了一個(gè)簡(jiǎn)單的HTML頁(yè)面布局,請(qǐng)看下圖:
??? 這個(gè)頁(yè)面有多個(gè)標(biāo)準(zhǔn)單元組成,就像頁(yè)面設(shè)計(jì)者和開(kāi)發(fā)者熟悉的那樣.這個(gè)頁(yè)面的主體由3個(gè)包含的單元組成:頁(yè)眉,頁(yè)內(nèi)容主體和頁(yè)腳.我們現(xiàn)在就看看這些單元并且了解如何使用模板標(biāo)簽系統(tǒng)來(lái)實(shí)現(xiàn).
頁(yè)主體
??? 下面的代碼單元顯示的是主體:
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:頁(yè)聲明
??? 第一個(gè)有趣的條目是頁(yè)頂部的頁(yè)聲明(1).我們?cè)陧?yè)面開(kāi)始聲明了這些變量,因此這些變量將能在下面的頁(yè)面和像頁(yè)眉那樣的包含頁(yè)所使用.
2:頁(yè)標(biāo)題
??? 下一步我們使用表達(dá)式來(lái)初始化頁(yè)面標(biāo)題(2).這個(gè)值能夠從配置文件中view-resources元素利用ViewResourcesConfig->getAppTitle來(lái)得到:
...
3:頁(yè)眉
??? 頁(yè)眉是下一個(gè)有趣的條目(3).在這里我們使用包含指令來(lái)插入頁(yè)眉模板文件到頁(yè)主體中.我們將在下一個(gè)子單元中來(lái)看一看頁(yè)眉.
??? 我們僅僅使用了頁(yè)面直接去讀取頁(yè)眉,不論頁(yè)的組件存儲(chǔ)在哪里.這是一個(gè)好機(jī)會(huì)來(lái)介紹模板標(biāo)簽系統(tǒng)的目錄設(shè)置.默認(rèn)情況下,模板目錄布局如下所示(注意這些路徑相對(duì)于我們的應(yī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結(jié)點(diǎn)來(lái)重新定義他們,就像這樣:
tplDir = "./WEB-INF/tpl-admin"
tplDirC = "./WEB-INF/tpl_admin_C"
...
4:頁(yè)內(nèi)容主體
??? 這是另外一個(gè)包含指令被用來(lái)插入模板文件(4)到主體中.注意包含的文件位于模板目錄的sales子目錄中:
"./WEB-INF/tpl/sale/pageContent.ssp"
5:頁(yè)腳
??? 又是一個(gè)包含指令,就像頁(yè)眉一樣.
頁(yè)眉單元
??? 在這個(gè)例子中頁(yè)眉模板文件('pageHeader.ssp')只是一個(gè)簡(jiǎn)單的單元,就像這樣:
?? <@ =viewConfig.getAppTitle @>
??? 當(dāng)主體頁(yè)面(包括包含的頁(yè)面)被編譯的時(shí)候,頁(yè)眉的表達(dá)式被轉(zhuǎn)換成下面這樣:
?? getAppTitle(); ?>
??? 被編譯的頁(yè)面被存儲(chǔ)在編譯模板目錄中,就像上面所說(shuō)的,默認(rèn)的編譯模板目錄是:
'./WEB-INF/tpl_C'
頁(yè)內(nèi)容主體單元
??? 頁(yè)內(nèi)容主體模板文件有一點(diǎn)復(fù)雜.文件('sale/pageContent.ssp')內(nèi)容顯示如下:
...
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:一些更多的聲明
??? 在頁(yè)面頂部所顯示的額外聲明(1)能讓我們聲明頁(yè)變量以便下面能夠使用.在內(nèi)容被處理之后,這些聲明將在編譯后像下面這樣顯示:
getValueBean("ITEM_1"); ?>
...
getValueBean("PRODUCTS_ARRAY"); ?>
2:使用表達(dá)式來(lái)顯示內(nèi)容單元標(biāo)題
??? 現(xiàn)在我們使用兩個(gè)表達(dá)式(2)來(lái)顯示內(nèi)容單元的標(biāo)題.注意我們聲明這些變量是"全局"變量在主頁(yè)面的頂部.處理完后,表達(dá)式將轉(zhuǎn)換這些代碼,就像這樣:
??? 當(dāng)頁(yè)面被顯示到用戶的瀏覽器中,內(nèi)容單元的標(biāo)題看起來(lái)就像這樣:
Jack's Super Deals for : May 2010.
3:使用表達(dá)式來(lái)顯示一些數(shù)據(jù)條目
??? 現(xiàn)在我們能顯示一些實(shí)際的數(shù)據(jù)(3).在這個(gè)頁(yè)內(nèi)容主體單元中我們?cè)L問(wèn)一些在PhpMVCTabAction類的ActionObject中的產(chǎn)品條目數(shù)據(jù).一個(gè)簡(jiǎn)化版的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)在能在模板頁(yè)面中被重新獲得:
<@ item1=data->getValueBean("ITEM_1") @>
??? 我們可以像下面那樣顯示條目的值:
<@ =item1.getName @>
...
<@ =item1.getCost @>
4:顯示數(shù)組
??? 我們也可以直接使用一些PHP代碼在我們的模板頁(yè)上.在這個(gè)分離的MVC模式中,我們應(yīng)該僅在這里編寫(xiě)代碼去操縱這些通過(guò)ActionObject和ViewResourcesConfig實(shí)例(可能我們的自定義Bean也可以)提供的數(shù)據(jù).在上面的也內(nèi)容單元('sale/pageContent.ssp')中,我們使用一個(gè)PHP的foreach語(yǔ)法(4)來(lái)循環(huán)讀取$products數(shù)組.我們能在上面的PhpMVCTabAction類中看到$products數(shù)組被創(chuàng)建并被保存在ActionObject中,就和上面的$item1 Bean相似.在foreach循環(huán)中我們能使用表達(dá)式來(lái)顯示產(chǎn)品數(shù)據(jù):
??
?????
???????? <@ =item.getName @>
?????
?????
???????? <@ =item.getCost @>
??????
??
5:顯示ViewResourcesConfig屬性
??? 最后我們從view-resources元素所定義的ViewResourcesConfig屬性來(lái)顯示"Area Manager"(5)在我們的內(nèi)容頁(yè):
...
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
