(2)WePHP 控制器与使用模板

 1 <?php
 2 class C_index extends Action
 3 {
 4     public function __initialize()
 5     {
 6         echo"自动执行";
 7     }
 8     public function index()
 9     {
10         echo "index";
11     }
12     public function test()
13     {
14         $a="我是模板";
15         $this->assign("example",$a);
16         $this->display();    
17     }
18 }
19 ?>
1.__initialize是自动执行方法,不管路由访问哪个控制器都会,实例化这个方法。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
{$example}
</body>
</html>

2.模板的目录结构  V(文件夹)—— 控制器名(文件夹)——方法名.html

3.两个模板常量

 {<$APP_URL>} 例子 :http://localhost/index.php/index/index

{<$APP_PATH>} 例子:http://localhost/index/

 
 
原文地址:https://www.cnblogs.com/saw2012/p/5226564.html