Home Backend Development PHP Tutorial PHP.MVC template tag system (4)_PHP tutorial

PHP.MVC template tag system (4)_PHP tutorial

Jul 21, 2016 pm 04:12 PM
use unit exist how layout Label template of system this page

页面布局

    在这个单元中我们将看到如何使用模板标签系统构造一个标准的模板页面。这个例子我们使用了一个简单的HTML页面布局,请看下图:

页面布局

    这个页面有多个标准单元组成,就像页面设计者和开发者熟悉的那样.这个页面的主体由3个包含的单元组成:页眉,页内容主体和页脚.我们现在就看看这些单元并且了解如何使用模板标签系统来实现.

页主体

    下面的代码单元显示的是主体:
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>  

  
  


     
  

  
  


     
  

  
  


     
  

        
4        <@ include 'sale/pageContent.ssp' @>
     


1:页声明
    第一个有趣的条目是页顶部的页声明(1).我们在页面开始声明了这些变量,因此这些变量将能在下面的页面和像页眉那样的包含页所使用.
2:页标题
    下一步我们使用表达式来初始化页面标题(2).这个值能够从配置文件中view-resources元素利用ViewResourcesConfig->getAppTitle来得到:
appTitle = "Flash Jacks' Sleek Tab Site"
...

3:页眉
    页眉是下一个有趣的条目(3).在这里我们使用包含指令来插入页眉模板文件到页主体中.我们将在下一个子单元中来看一看页眉.
    我们仅仅使用了页面直接去读取页眉,不论页的组件存储在哪里.这是一个好机会来介绍模板标签系统的目录设置.默认情况下,模板目录布局如下所示(注意这些路径相对于我们的应用程序):
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:使用表达式来显示内容单元标题
    现在我们使用两个表达式(2)来显示内容单元的标题.注意我们声明这些变量是"全局"变量在主页面的顶部.处理完后,表达式将转换这些代码,就像这样:

    当页面被显示到用户的浏览器中,内容单元的标题看起来就像这样:
Jack's Super Deals for : May 2010.
3:使用表达式来显示一些数据条目
    现在我们能显示一些实际的数据(3).在这个页内容主体单元中我们访问一些在PhpMVCTabAction类的ActionObject中的产品条目数据.一个简化版的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被创建并被保存成ActionObject的valueBeans条目.Bean数据条目现在能在模板页面中被重新获得:
<@ item1=data->getValueBean("ITEM_1") @>
    我们可以像下面那样显示条目的值:
<@ =item1.getName @>
...
<@ =item1.getCost @>
4:显示数组
    我们也可以直接使用一些PHP代码在我们的模板页上.在这个分离的MVC模式中,我们应该仅在这里编写代码去操纵这些通过ActionObject和ViewResourcesConfig实例(可能我们的自定义Bean也可以)提供的数据.在上面的也内容单元('sale/pageContent.ssp')中,我们使用一个PHP的foreach语法(4)来循环读取$products数组.我们能在上面的PhpMVCTabAction类中看到$products数组被创建并被保存在ActionObject中,就和上面的$item1 Bean相似.在foreach循环中我们能使用表达式来显示产品数据:

  
     
         <@ =item.getName @>
     
     
         <@ =item.getCost @>
      
  

5:显示ViewResourcesConfig属性
    最后我们从view-resources元素所定义的ViewResourcesConfig属性来显示"Area Manager"(5)在我们的内容页:
appTitle = "Flash Jacks' Sleek Tab Site"
...
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) {

$this->areaManager = $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

truehttp: //www.bkjia.com/PHPjc/313701.htmlTechArticlePage Layout In this unit we will see how to construct a standard template page using the template tag system. For this example we use a simple HTML page layout, please see the picture below...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What software is crystaldiskmark? -How to use crystaldiskmark? What software is crystaldiskmark? -How to use crystaldiskmark? Mar 18, 2024 pm 02:58 PM

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

CUDA's universal matrix multiplication: from entry to proficiency! CUDA's universal matrix multiplication: from entry to proficiency! Mar 25, 2024 pm 12:30 PM

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

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

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

How to download foobar2000? -How to use foobar2000 How to download foobar2000? -How to use foobar2000 Mar 18, 2024 am 10:58 AM

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

How to use NetEase Mailbox Master How to use NetEase Mailbox Master Mar 27, 2024 pm 05:32 PM

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

How to use Baidu Netdisk app How to use Baidu Netdisk app Mar 27, 2024 pm 06:46 PM

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.

BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? BTCC tutorial: How to bind and use MetaMask wallet on BTCC exchange? Apr 26, 2024 am 09:40 AM

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

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Jun 02, 2024 pm 02:58 PM

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

See all articles