Home >php教程 >PHP开发 >PHP.MVC template tag system (4)

PHP.MVC template tag system (4)

黄舟
黄舟Original
2016-12-17 10:11:401083browse

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:

PHP.MVC template tag system (4)

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






<br>2 " <br> " 'pageLayoutTable'><br><br> <!-- PAGE HEADER --> <tr> <p> </p> <td class="pageHeader"> <!-- The base template base directory is "./tpl" --><p>3  <br>  </p> </td> <br> </tr> <br><br> <br> <tr valign="top"> <br> ; <td class="pageContent"> <br> ; <!-- including the page contents component -->4 <p>                                                                                                                                                                              '><br> ' ' <br><br><br><br></p> <p>1: Page Declaration<br> 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. .<br>2: Page title<br> 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: <br><view-resources></view-resources> appTitle = "Flash Jacks' Sleek Tab Site"<br> ...<br><br>3: Header<br> 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. <br> 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): <br>The Default phpMVC_Tags Template Directory Layout Paths (relative) <br>The Template Files './WEB-INF/tpl' <br>The Compiled Template Files './WEB-INF/tpl_C' <br> If necessary we can redefine them in the view-resources node of the configuration file, like this: <br><view-resources></view-resources> ...<br> tplDir = "./WEB-INF/tpl-admin"<br> tplDirC = "./WEB-INF/tpl_admin_C"<br> ...<br><br>4: Page content body<br> 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:<br>"./WEB-INF/tpl/sale/pageContent.ssp"<br>5: Footer<br> Another one Contains directives, just like a page header.</p> <p>Header unit</p> <p> In this example the header template file ('pageHeader.ssp') is just a simple unit, like this:<br><!-- Page Header - -><br/><span><br/> When the main page (including included pages) is compiled, the header expression is converted to the following :<br/><!-- Page Header --><br><span><br> <?php PRint $viewConfig->getAppTitle(); ?><br></span><br> The compiled page is stored in In the compiled template directory, as mentioned above, the default compiled template directory is: <br>'./WEB-INF/tpl_C'<br><br>Page content main unit</p> <p> The page content main template file is a bit complicated. File ('sale /pageContent.ssp') content is displayed as follows: </p>...<p>1<br>getValueBean("ITEM_1") @><br>getValueBean("PRODUCTS_ARRAY" ) @><br><br>2</p> <h4> </h4> <p><br>3</p> <b>Clearance deals</b><p><br>                                                                       ue' > class ='productsTable'><br><?php foreach($products as $item) { ?><br> </p> </td> </tr> <tr> <br> <td class="prodItemDesc"> <br> <br>                                                                        <br> <br><p><b>Our Staff at Your Service</b><br>...<br>5<br></p> <table class="productsTable"> <br> <tr> <br>  <td class="prodItemDesc"> <br>  Area Manager: <br>  </td> <br>  <td class="prodItemDesc"> <br>  <br>  </td> <br> </tr> <br> ...<br> </table> <br>1: Some more declarations <br> 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: <br><?php $item1=$data->getValueBean("ITEM_1"); ?><br>...<br><?php $products=$data->getValueBean( "PRODUCTS_ARRAY"); ?><br>2: Use expressions to display the title of the content unit<br> 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: <br><?php print $dealHeading; ?> <?php print $saleMonth; ?><br> When the page is displayed to the user's browser In the browser, the title of the content unit looks like this: <br>Jack's Super Deals for : May 2010. <br>3: Use expressions to display some data items <br> 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: <br>class PhpMVCTabAction extends Action { <br> ...<br> function execute($mapping, $form, &$request . .xml file.<br> // See: ExtendedController example.<br> $appTitle = "Flash Jack's Include Page"; $saleMonth = "May 2010";<p> $saleTitle = "Flash Jack's Super Sale";<br> $ dealHeading = "Jack's Super Deals for: ";<br>                                                                                                                                                                                                              AddValueBean saleMonth);<br> $valueBeans->addValueBean('SALE_TITLE' , $saleTitle);<br> $valueBeans->addValueBean('DEAL_HEADING' , $dealHeading);<br> ...<br><br> we could receive from a database query</p>                                                                                                             The prices are formatted in                                                                                                                                   . Individual object instances: <p> //note: The Product Class File WAS Included in Our Local Prepend.php File<br> $ ITEM1 = New PRODUCT ('Super Duper', $ PRI CE1); ('ITEM_1', $item1);<br>                                                                                                                                                    :... </p> <p><br>            // Save the Value object<br>                                                                                                                                       saveValueObject($request, $ $valueBeans);                                                                             $item1 Now it can be retrieved in the template page: <br>getValueBean("ITEM_1") @><br> We can display the value of the item like this: </p>...<br><br>4: Display array<br> 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: <br><?php foreach($products as $item) { ?><br> </td> </tr> <tr> <br> ;/td><br>                                                                              Display the ViewResourcesConfig attribute <br> Finally, we display the "Area Manager" (5) from the ViewResourcesConfig attribute defined by the view-resources element on our content page: <br><view-resources></view-resources> appTitle = "Flash Jacks' Sleek Tab Site"<br> . ..<br>          className                                                                                                                                                          ."/><br> <br> 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: <br>class MyViewResourcesConfig extends ViewResourcesConfig {<br><br> // ----- Properties --------------------- -------------------------------- //<br><br> var $areaManager = '';<br><br> function getAreaManager() { <br>          return $this->areaManager;<br>                                                                                                                                                                                                                                              been been Being -- function setAreaManager($areaManager) {      :<br><br> Note: In a real application the data can be obtained from a relational database.<p>Footer unit<br></p> <p> The footer unit is handled similarly to the header unit discussed above. The footer template file ('tpl/pageFooter.ssp') looks like this: <br><!-- Page Footer --><br><span></span> <br><br> When the main page (including included pages) is compiled, the expression in the footer is converted to the following:<br><!-- Page Footer --><br><span><br> <?php print $viewConfig->getCopyright(); ?><br></span> <br> The compiled header page is stored in the compiled template directory. Default The compiled template directory is: <br>'./WEB-INF/tpl_C'</p> <p> 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)! <br></p> <p><br></p> </tr>
Statement:
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