PHP.MVC template tag system (3)_PHP tutorial

WBOY
Release: 2016-07-21 16:12:32
Original
837 people have browsed it

PHP.MVC标签语法

    在基本的介绍之后,我们现在就可以来看看模板标签系统的语法.
    在看具体的标签之前,我们应该定义什么作为我们的标签.为了写一个标签,我们使用<@ ... @>标签结点.左标签(<@)和右标签(@>)是默认的标签.如果必要的话,这些标签我们能够在phpmvc-config.xml中重新定义.
    模板标签系统现在支持以下3种标签:包含指令,声明和表达式.我们现在来看看这些指令.

包含指令

    包含指令能让我们将内容分隔为许多模块,比如:页眉,页脚或者内容.包含的页面可以是HTML,或者其他标签模板页.据个例子,下面的包含指令能用来包含一个页眉:
    <@ include 'pageHeader.ssp' @>
    一个包含指令在模板上下文种的例子:


...




  
     
  
  
   ...
  
   ...

...



    在这里例子种pageHeader.ssp页眉文件内容将被插入到主页面上当这个页面被发送到用户浏览器上.这个页眉文件包含了一个表达式:

 
    <@ =viewConfig.getAppTitle @>
 

    这个表达式将被编译并且将在运行时输出为:

 
    Flash Jacks' Sleek Tab Site
 

声明

    声明允许我们在模板种声明一个页面级别的变量,或者甚至其他包含页面.一个声明看起来像以下代码:
    <@ salesAreaID = "Central District" @>
    我们能够在模板文件中使用声明:
<@ saleMonth = data.getValueBean('SALE_MONTH') @>
<@ saleTitle = data.getValueBean('SALE_TITLE') @>
<@ dealHeading = data.getValueBean('DEAL_HEADING') @>
<@ salesAreaID = "Central District" @>



  
   <br>      ...<br>  


...


    在这里例子中,我们声明了一些页变量.前3个变量已经在我们创建的Action类中的ActionObject中被赋值:data.getValueBean('SALE_MONTH').第4个变量被赋了一个字符串值:salesAreaID = "Central District".
    声明的变量现在可以在页面中使用了:

...

<@=dealHeading @> <@=saleMonth @>


Clearance deals

   ...


Todays specials

   ...


...

    这些页变量将被输出为:

Jack's Super Deals for : May 2010


...
...

表达式

The expression tag allows us to execute expressions in the template page. The result of the expression will be included in the template page. The following expression will be used to display a simple string (salesAreaID) and can also retrieve the framework configuration Class attributes:
<@ =salesAreaID @>
<@ =viewConfig.contactInfo @>
In order to use these expressions, we have to declare before:
<@ salesAreaID = "Central District" @>
Or the properties of the ViewResourcesConfig object (viewConfig) are declared in the view-resources node:
appTitle = "Flash Jacks' Sleek Tab Site"
contactInfo = "flash.jack@jackshost.com"
...

When using an object in an expression, we can write an object - Methods (object-method) are declared in standard PHP notation or dot-style notation:
The PhpMVC_Tags Object-Method Notation
PHP Style sales = data->getSales
Dot Style sales = data.getSales
With Method Params staff = data.getValueBean("STAFF")
Retrieve Data Array products = data->getValueBean("PRODUCTS_ARRAY")
In the next unit we will see how to use the template tag system to convert these Combined together to build the page.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/313704.htmlTechArticlePHP.MVC tag syntax After the basic introduction, we can now take a look at the syntax of the template tag system. Before looking at the specific tags, we should define what to use as our tags. In order to...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!