合作&赞助



管理员登录
用户名:
密 码:
技术文章 > PHP

thinkphp留言板(二)
Description:为了提升一层次,决定尝试thinkphp开发个项目. 不过咱啥也不懂,先看看实例。。。
Source Url:http://hi.baidu.com/waterjiang/blog/item/600d4e802cd827ab0cf4d2d1.html
       项目创建完后,lib文件夹下面的Action文件夹下面会生成一个IndexAction.class.php文件,里面会有一个IndexAction的类index就是操作IndexAction类的一个方法。这里我们称之为控制器。

      接下来就是开始写程序呢。首先确定思路,然后设计数据库and把界面拉出来,现在就用table直接套,不加任何样式。

一:

1):在Tpl文件下面的default文件夹下面建立一个index文件夹,在index文件夹里做界面。建立的这个index文件夹名必须与其控制器的名称相对应。

我们做网页一般分三部分,header,bottom,center

2)我们先把头做出来,建立一一个head.html文件,输入如下代码:

<table width="562" border="1" align="center">
<tr>
    <td colspan="2" align="center">清清留言板</td>
</tr>
<tr>
    <td width="230" align="right"><a href="__URL__/index">浏览留言</a></td>
    <td width="230" align="left"><a href="__URL__/add">发布留言</a></td>
</tr>
</table>

效果: 

暂且不管连接。
3)再做网页center部分。建立index.html文件,为浏览留言页面,输入如下代码:

<!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>
<include file="Index:head" />
<table width="562" height="118" border="1" align="center">
<tr>
    <td width="97" rowspan="2">&nbsp;</td>
    <td width="286" height="36">主题:</td>
    <td width="59"><a href="
mailto:waterjiang@yahoo.cn " target="_blank">邮箱</a></td>
    <td width="92"><A target="blank" href="tencent://message/?uin=274032290&Menu=yes"><IMG border="0" src="
http://wpa.qq.com/pa?p=1:274032290:1" alt="有事点这里"></A></td>
</tr>
<tr>
    <td height="74" colspan="3">&nbsp;</td>
</tr>
</table>
<include file="Index:bottom"/>

</body>
</html>

效果:

<include file="Index:head" />相当于php中的include函数。

4)最后做一个网站底部bottom.html

<table width="562" border="1" align="center">
<tr>
    <td colspan="2" align="center">技术支持:清清工作室。版权所有:2009——2010 爱网网络公司</td>
</tr>
</table>

效果:

 

5)然后打开控制器IndexAction.class.php:

class IndexAction extends Action{
    public function index(){
   $this->display();
    }

}

运行index.phpl就可以看到就面效果了:



 

6)最后再做一个发布页面。add.html

<!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>
<include file="Index:head"/>
<form action="__URL__/insert/" method="post">
<table width="562" border="1" align="center">
<tr>
    <td width="155" rowspan="7">这里有时间加个选择图像的</td>
    <td width="88">留言人</td>
    <td width="297"><input type="text" name="name" id="name"/></td>
</tr>
<tr>
    <td>Email</td>
    <td><input type="text" name="email" /></td>
</tr>
<tr>
    <td>QQ</td>
    <td><input type="text" name="qq" /></td>
</tr>
<tr>
    <td>留言主题</td>
    <td><input type="text" name="title" /></td>
</tr>
<tr>
    <td>留言内容</td>
    <td><textarea name="con" cols="40" rows="5"></textarea></td>
</tr>
   <tr>
    <td>验证码</td>
    <td><input type="text" /><img src="__URL__/ma" /></td>
</tr>

<tr>
    <td colspan="2" align="center"><input type="submit" value=" 提 交 " />&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value=" 重 置 " /></td>
    </tr>
</table>
</form>
<include file="Index:bottom"/>
</body>
</html>


这样前台页面就做完了。丑是丑,但练习还是冇问题的。



使用时间:0.0120730400085 秒