3
<b>Clearance deals</b>
<table>
<tr>
<td>
<@ =item1.getName @>
</td>
<td>
<@ =item1.getCost @>
</td>
</tr>
</table>
4
<b>Todays specials</b>
<table>
<?php foreach($products as $item) { ?>
<tr>
<td>
<@ =item.getName @>
</td>
<td>
<@ =item.getCost @>
</td>
</tr>
<?php } ?>
</table>
<b>Our Staff at Your Service</b>
...
5
<table>
<tr>
<td>
<b>Area Manager: </b>
</td>
<td>
<@ =viewConfig.getAreaManager @>
</td>
</tr>
...
</table>
1:一些更多的声明
在页面顶部所显示的额外声明(1)能让我们声明页变量以便下面能够使用.在内容被处理之后,这些声明将在编译后像下面这样显示:
<?php $item1=$data->getValueBean("ITEM_1"); ?>
...
<?php $products=$data->getValueBean("PRODUCTS_ARRAY"); ?>
2:使用表达式来显示内容单元标题
现在我们使用两个表达式(2)来显示内容单元的标题.注意我们声明这些变量是"全局"变量在主页面的顶部.处理完后,表达式将转换这些代码,就像这样:
<?php print $dealHeading; ?> <?php print $saleMonth; ?>
当页面被显示到用户的浏览器中,内容单元的标题看起来就像这样:
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);