---
title: "PHP框架queryphp教程：入门六 视图模板"
author: "web001"
date: "2012-12-10T11:42:16Z"
tags: []
categories: ["编程语言"]
slug: "php-queryphp"
draft: false
lastmod: "2012-12-10T11:42:16Z"
id: 1744857
url: "https://web001.iteye.com/blog/1744857"
---

## 使用原生php代码标签

看手册： 

PHP 提供了一些流程控制的替代语法，包括 if，while，for，foreach 和 switch。

替代语法的基本形式是把左花括号（{）换成冒号（:），把右花括号（}）

分别换成 endif;，endwhile;，endfor;，endforeach; 以及 endswitch;。 

还有不少可以做标签呢 

url\_for()为url地址修改函数请使用这个函数设置地址 

模板标签使用url\_for()函数例子:

&lt;ul&gt;

&lt;li&gt;&lt;a href="&lt;?php echo url\_for("curd/create")?&gt;"&gt;添加新记录&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="&lt;?php echo url\_for("curd/index")?&gt;"&gt;数据列表&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

url\_for();多加一个true参数是一定会返回动态地址

&lt;form id="form1" name="form1" method="post" action="&lt;?php echo url\_for("curd/createForm",true);?&gt;"&gt;

 

模板标签使用 foreach循环例子:

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; 

&lt;head&gt; 

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; 

&lt;title&gt;CURD演示&lt;/title&gt; 

&lt;/head&gt; 

&lt;body&gt; 

&lt;ul&gt; 

&lt;li&gt;&lt;a href="&lt;?php echo url\_for("curd/create")?&gt;"&gt;添加新记录&lt;/a&gt;&lt;/li&gt; 

&lt;li&gt;&lt;a href="&lt;?php echo url\_for("curd/index")?&gt;"&gt;数据列表&lt;/a&gt;&lt;/li&gt; 

&lt;/ul&gt; 

&lt;table width="400" border="0" cellspacing="0" cellpadding="0"&gt; 

  &lt;tr&gt; 

    &lt;td&gt;序号&lt;/td&gt; 

    &lt;td&gt;类名&lt;/td&gt; 

    &lt;td&gt;typeid&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

  &lt;/tr&gt; 

  &lt;?php foreach($list as $key=&gt;$value):?&gt; 循环开始注意:号

  &lt;tr&gt; 

    &lt;td&gt;&lt;?php echo $value\['bookid'];?&gt;&lt;/td&gt; 

    &lt;td&gt;&lt;?php echo $value\['classname'];?&gt;&lt;/td&gt; 

    &lt;td&gt;&lt;?php echo $value\['typeid'];?&gt;&lt;/td&gt; 

    &lt;td&gt;&lt;a href="&lt;?php echo url\_for("curd/show/id/".$value\['bookid'])?&gt;"&gt;显示&lt;/a&gt;&lt;/td&gt; 

    &lt;td&gt;&lt;a href="&lt;?php echo url\_for("curd/edit/id/".$value\['bookid'],true)?&gt;"&gt;编辑&lt;/a&gt;&lt;/td&gt; 

    &lt;td&gt;&lt;a href="&lt;?php echo url\_for("curd/delete/id/".$value\['bookid'],true)?&gt;"&gt;删除&lt;/a&gt;&lt;/td&gt; 

  &lt;/tr&gt; 

  &lt;?php endforeach;?&gt;//循环结束

  &lt;tr&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

    &lt;td&gt;&nbsp;&lt;/td&gt; 

  &lt;/tr&gt; 

&lt;/table&gt; 

&lt;span&gt; 

&lt;?php 

echo $pager-&gt;getWholeBar(url\_for("curd/index/page/:page")); //输出分页导航 :page 将会被分页页数替换

?&gt; 

&lt;/span&gt; 

&lt;/body&gt; 

&lt;/html&gt;