# 模板的定義
## 默認模板
默認的情況下,模板文件與控制方法有著對應關系。
例如:假設應用目錄為app
| 控制器方法 |模板文件 |
| -- | -- | -- |
|Index/index|/app/View/Index/index.php|
|Index/list|/app/View/Index/list.php|
|Public/login|/app/View/Public/login.php|
|Public/reg|/app/View/Public/reg.php|
|User/index|/app/View/User/index.php|
|User/edit|/app/View/User/edit.php|
<br/><br/>
#### 控制器示例代碼:/app/Controller/IndexController.php
~~~
class IndexController extends Controller{
public function index(){
$this->display();
}
}
~~~
#### 模板示例代碼:/app/View/Index/index.php
~~~
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>MAGPHP框架</title>
</head>
<body>
歡迎使用MAGPHP微框架!
</body>
</html>
~~~
<br/><br/>
## 指定模板
如果需要指定一個模板文件,則需要給display()方法指定 **第二個參數**,參數為模板文件的 **路徑** 或 **控制器和方法名** 。
(這里我們先不管第一個參數,只是設定為 空,在 <span style="color:red;">模板中變量與賦值</span> 章節會對第一個參數詳細說明)
#### 指定路徑的方式:
~~~
$this->display('', './app/Views/Index/index.php');
$this->display('', './app/Views/Goods/list.php');
$this->display('', './app/Views/User/index.php');
$this->display('', './app/Views/User/get.php');
~~~
#### 控制器和方法的方式:
以下效果與上面路徑方式一一對應,效果完全一樣。
~~~
$this->display('', 'Index/index');
$this->display('', 'Goods/list');
$this->display('', 'User/index');
$this->display('', 'User/get');
~~~
<br/><br/>