經過咱們不懈的努力之下咱們自己編寫的MVC終於封裝完成了,那麼究竟好不好用需要我們實際操作一下。那麼我們接下來我們通過一個小項目來檢驗一下,我們接下來就做一個留言板項目。
下面是我們的數據庫設計:
控制器代碼:
<?php
namespace app\ctrl;
class indexCtrl extends \core\ZL
{
//所有留言
public function index()
{
$this->display('index.html');
}
//添加留言
public function add()
{
$this->display('add.html');
}
//保存留言
public function save()
{
}
}
model代碼:
<?php
namespace app\model;
use core\lib\model;
class liuyanModel extends model
{
public $table = 'liuyan';
//查詢
public function all()
{
}
public function addOne()
{
}
}
?>
layout.html(視圖模板)代碼:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
</head>
<body>
<header class="am-topbar am-text-center">
<h1 class="am-sm-12">超簡單留言板</h1>
<div class="am-g">
<a class="am-btn-default" href="/">所有留言</a>
<a class="am-btn-default" href="/index.php/index/add">添加留言</a>
</div>
</header>
<div class="am-g content">
{% block content %}
{% endblock %}
</div>
<footer class="footer">
<p>© 2016 超簡單留言板</p>
</footer>
</body>
</html>
留言展示index.html代碼:
{% extends "layout.html" %}
{% block content %}
<ul>
<li class="am-u-sm-3">
<div>
<h1>tile</h1>
<p>content</p>
<p><span>2015-12-12</span></p>
<a href="">查看全文</a>
</div>
</li>
</ul>
{% endblock %}
留言添加add.html代碼:
{% extends "layout.html" %}
{% block content %}
<form action="" method="post" class="am-form">
<filedest>
<legend>添加留言</legend>
<div class="am-form-group">
<input type="text" name="title" class="" placeholder="請輸入Title">
</div>
<div class="am-form-group">
<textarea name="title" class="" placeholder="請輸入content">
</textarea>
</div>
<p><button type="submit" class="am-btn-default">提交</button></p>
</filedest>
</form>
{% endblock %}