Smarty案例----新聞管理系統
1、創建數據庫
2、連接數據庫
//第一種方式
$host="localhost";
$host="root";
$host="";
$host="new";
$mysqli=new mysqli("localhost","root","","new");
$mysqli->query("set names utf8");
//第二種方式
/*class mysql{
var $host="localhost";
var $host="root";
var $host="";
var $host="new";
function connect(){
$mysql=new mysqli($this->host,$this->username,$this->password,
$this->dbname);
if(mysqli_connect_errno()){
echo "連接數據庫失敗";
exit;
}
return $mysqli;
}
}
美工:使用html,這是模板文件
關於MVC
1、 採用的技術---smarty(V)
2、 搭建的開發環境----wamp
目錄介紹
文件與文件之間的關係
每個文件解決的問題
功能介紹---PHP(M+C)
M:處理方法
通過init.inc.php連接html和php文件
<?php
include("./libs/Smarty.class.php");
$tpl=new Smarty();
$tpl->template_dir='templates';
$tpl->compile_dir='templates_c';
$tpl->left_delimiter='<{';
$tpl->right_delimiter='}>';
C:條件
3、 界面---------TPL (V)
登陸界面:
<p id="title">新聞管理登陸</p>
<form name="myform"
action="../new_manage/login.php" method="post">
<table width=280 border="0">
<tr>
<td>用戶名:</td>
<td><input type="text" name="username" ></td>
</tr>
<tr>
<td>密碼:</td>
<td><input type="password"
name="password"></td>
</tr>
</table>
<input type="submit" value="提交" name="submit">
</form>