欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)的簡(jiǎn)單留言板功能示例【基于thinkPHP框架】

 更新時(shí)間:2018年12月07日 12:06:55   作者:luckymaoyy  
這篇文章主要介紹了PHP實(shí)現(xiàn)的簡(jiǎn)單留言板功能,結(jié)合實(shí)例形式分析了基于thinkPHP框架實(shí)現(xiàn)的留言板相關(guān)配置、數(shù)據(jù)庫操作、sql語句等實(shí)現(xiàn)技巧與操作注意事項(xiàng),需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)的簡(jiǎn)單留言板功能。分享給大家供大家參考,具體如下:

入口文件  文件名 index.php

<?php
// 應(yīng)用入口文件
// 檢測(cè)PHP環(huán)境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// 開啟調(diào)試模式 建議開發(fā)階段開啟 部署階段注釋或者設(shè)為false
define('APP_DEBUG',True);//開發(fā)調(diào)試模式
//define('APP_DEBUG',false);//生產(chǎn)模式
// 定義應(yīng)用目錄
define('APP_PATH','./Message/');
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
// 親^_^ 后面不需要任何代碼了 就是如此簡(jiǎn)單

配置文件 文件名 config.php

<?php
return array(
  //'配置項(xiàng)'=>'配置值'
  'SHOW_PAGE_TRACE'=>true,
  'DB_TYPE'        => 'mysqli',   // 數(shù)據(jù)庫類型
  'DB_HOST'        => '127.0.0.1', // 服務(wù)器地址
  'DB_NAME'        => 'msg',     // 數(shù)據(jù)庫名
  'DB_USER'        => 'root',   // 用戶名
  'DB_PWD'        => 'root',     // 密碼
  'DB_PORT'        => '3306',    // 端口
  'DB_PREFIX'       => 'ms_',  // 數(shù)據(jù)庫表前綴
);

控制器  文件名 MsgController.class.php

<?php
namespace Home\Controller;
use Think\Controller;
use Think\Model;
class MsgController extends Controller{
  public function index(){
    $msg = D('Msg');
    $info = $msg->order('id DESC')->select();
    $this->assign('info',$info);
    $this->display();
  }
  public function sendMsg(){
    $msg = new \Home\Model\MsgModel();
    if (!empty($_POST)){
      $data = $msg->create();
      if($data){
        $data['user_hobby'] = implode(',',$data['user_hobby']);
        $z = $msg->add($data);
        if ($z){
          $this->redirect('Msg/sendMsg');
        }
      }else{
        $this->assign('errorInfo',$msg->getError());
      }
    }
    $this->display();
  }
  public function upd($id){
    $msg = D('Msg');
    if (!empty($_POST)){
      $z = $msg->save($_POST);
      if ($z){
        $this->redirect('index',array(),2,'修改成功');
      }else{
        $this->redirect('upd',array('id'=>$id),2,'修改失敗');
      }
    }else{
      $info = $msg->find($id);
      $this->assign('info',$info);
      $this->display();
    }
  }
  public function addMsg(){
    $msg = D('Msg');
    if (!empty($_POST)){
      $z = $msg->add($_POST);
      if ($z){
        $this->redirect('index',array(),2,'添加成功');
      }else{
        $this->redirect('addMsg',array(),2,'添加失敗');
      }
    }else{
      $this->display();
    }
  }
  public function del($id){
    if(D('Msg')->delete($id)){
      $this->success('成功',U('index'),2);
    }else{
      $this->error('失敗',U('index'),2);
    }
  }
}

模板  文件名 MsgModel.class.php

<?php
namespace Home\Model;
use Think\Model;
class MsgModel extends Model{
  //是否批量驗(yàn)證
  protected $patchValidate = true;
  protected $_validate = array(
    array('title','require','標(biāo)題不能為空!'), //默認(rèn)情況下用正則進(jìn)行驗(yàn)證
    array('user','require','留言人不能為空!'),
    array('msg','require','內(nèi)容不能為空!'),
  );
  protected $_auto = array (
    array('status','1'), // 新增的時(shí)候把status字段設(shè)置為1
    array('id','NULL'),
    array('admin_user','ms'),
    array('replay','NULL'),
    array('update_time','time',3,'function'), // 對(duì)update_time字段在更新的時(shí)候?qū)懭氘?dāng)前時(shí)間戳
    array('send_msg_time','time',3,'function'),
  );
}

視圖  文件名 addMsg.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div>
  <form action="__SELF__" method="post" >
    <table border="1" width="100%" class="table_a">
      <tr>
        <td>留言時(shí)間</td>
        <td><input type="text" name="update_time"/></td>
      </tr>
      <tr>
        <td>留言人</td>
        <td><input type="text" name="user" /></td>
      </tr>
      <tr>
        <td>標(biāo)題</td>
        <td><input type="text" name="title" /></td>
      </tr>
      <tr>
        <td>內(nèi)容</td>
        <td><input type="text" name="msg" /></td>
      </tr>
      <tr>
        <td>回復(fù)</td>
        <td><textarea name="replay"></textarea></td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input type="submit" value="添加">
          <a href="__CONTROLLER__/index" rel="external nofollow" rel="external nofollow" ><input type="button" value="返回"></a>
        </td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>

視圖  文件名 index.html

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>留言列表 -- HoverTree</title>
  <style>
    .keleyitable {
      width: 800px;
    }
    .keleyitable table, td, th {
      border: 1px solid green;margin-top:10px;
    }
    .klytd {width:100px;text-align:right
    }
    .hvttd {
      width:500px}
  </style>
</head>
<body>
<div style="margin:0px auto;" class="keleyitable"><h2>留言列表</h2>
  <tr><td class="klytd"><a href="__CONTROLLER__/addMsg" rel="external nofollow" >添加</a></td><td class="hvttd"></td></tr>
  <volist name="info" id="vo">
    <table>
      <tr><td class="klytd">留言時(shí)間:</td><td class="hvttd">{$vo.update_time|date="Y-m-d H:i:s",###}</td></tr>
      <tr><td class="klytd">留言人:</td><td class="hvttd">{$vo.user}</td></tr>
      <tr><td class="klytd">標(biāo)題:</td><td class="hvttd">{$vo.title}</td></tr>
      <tr><td class="klytd">內(nèi)容:</td><td class="hvttd">{$vo.msg}</td></tr>
      <tr><td class="klytd">回復(fù):</td><td class="hvttd">{$vo.replay}</td></tr>
    </table>
    <tr><td class="klytd"><a href="__CONTROLLER__/upd/id/{$vo.id}" rel="external nofollow" >修改</a></td><td class="hvttd"></td></tr>
    <tr><td class="klytd"><a href="__URL__/del/id/{$vo.id}" rel="external nofollow" >刪除</a></td><td class="hvttd"></td></tr>
  </volist>
</div>
<div style="width:800px;margin:10px auto;font-family:Arial, Helvetica, sans-serif;text-align:center;">HoverTree &copy; 2014 keleyi.com </div>
<!--最近打算開發(fā)一個(gè)留言板,asp.net的開源項(xiàng)目,http://hovertree.codeplex.com -->
</body>
</html>

視圖  文件名 sendMsg.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
  <form action="" method="post">
    標(biāo)&nbsp;&nbsp;&nbsp;題: <input type="text" name="title"><span style="color:red;">{$errorInfo.title}</span><br><br>
    信&nbsp;&nbsp;&nbsp;息: <input type="text" name="msg"><span style="color:red;">{$errorInfo.msg}</span><br><br>
    留言人: <input type="text" name="user"><span style="color:red;">{$errorInfo.user}</span><br><br>
    <input type="submit" value="提交">
  </form>
</body>
</html>

視圖 文件名  upd.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<div>
  <form action="__SELF__" method="post" >
    <input type="hidden" name="id" value="{$info.id}">
    <table border="1" width="100%" class="table_a">
      <tr>
        <td>留言時(shí)間</td>
        <td><input type="text" name="update_time" value="{$info.update_time}" /></td>
      </tr>
      <tr>
        <td>留言人</td>
        <td><input type="text" name="user" value="{$info.user}" /></td>
      </tr>
      <tr>
        <td>標(biāo)題</td>
        <td><input type="text" name="title" value="{$info.title}" /></td>
      </tr>
      <tr>
        <td>內(nèi)容</td>
        <td><input type="text" name="msg" value="{$info.msg}" /></td>
      </tr>
      <tr>
        <td>回復(fù)</td>
        <td><textarea name="replay">{$info.replay}</textarea></td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input type="submit" value="修改">
          <a href="__CONTROLLER__/index" rel="external nofollow" rel="external nofollow" ><input type="button" value="返回"></a>
        </td>
      </tr>
    </table>
  </form>
  </div>
</body>
</html>

目錄結(jié)構(gòu)

數(shù)據(jù)庫 sql語句

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- 資料庫: `msg`
--
-- --------------------------------------------------------
--
-- 表的結(jié)構(gòu) `ms_msg`
--
CREATE TABLE IF NOT EXISTS `ms_msg` (
 `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主鍵',
 `admin_user` varchar(100) NOT NULL COMMENT '管理員',
 `update_time` int(10) NOT NULL COMMENT '更新時(shí)間',
 `status` int(2) NOT NULL COMMENT '狀態(tài)',
 `send_msg_time` int(10) NOT NULL COMMENT '留言時(shí)間',
 `user` varchar(100) NOT NULL COMMENT '留言人',
 `title` varchar(100) NOT NULL COMMENT '標(biāo)題',
 `msg` varchar(200) NOT NULL COMMENT '內(nèi)容',
 `replay` varchar(200) NOT NULL COMMENT '回復(fù)',
 PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='留言表' AUTO_INCREMENT=19 ;
--
-- 轉(zhuǎn)存資料表中的資料 `ms_msg`
--
INSERT INTO `ms_msg` (`id`, `admin_user`, `update_time`, `status`, `send_msg_time`, `user`, `title`, `msg`, `replay`) VALUES
(1, 'ms', 1479449110, 1, 1479449110, '1', '拉克絲的減肥', '對(duì)方科目了', 'NULL'),
(7, '', 321423432, 0, 0, 'kljflwk', 'kjsdfnlk', 'nlkdsjfn', 'kljnf'),
(3, 'ms', 1479451017, 1, 1479451017, '1', '輕松的發(fā)生我', '沃爾沃飛', 'NULL'),
(8, 'ms', 1479544687, 1, 1479544687, '', 'qwe', '', 'NULL'),
(9, 'ms', 1479544693, 1, 1479544693, 'qwe', 'qwe', 'qwe', 'NULL'),
(10, 'ms', 1479544970, 1, 1479544970, 'qwe', 'qwe', 'qwe', 'NULL'),
(11, 'ms', 1479544979, 1, 1479544979, '12', '12', '12', 'NULL'),
(12, 'ms', 1479545029, 1, 1479545029, '12', '12', '12', 'NULL'),
(13, 'ms', 1479546357, 1, 1479546357, '12', '12', '12', 'NULL'),
(14, 'ms', 1479547163, 1, 1479547163, '12', '12', '12', 'NULL'),
(16, 'ms', 1479547667, 1, 1479547667, '12', '12', '123', 'NULL'),
(17, 'ms', 2147483647, 1, 1479547682, '上來昆明3', '說的了付款', '藍(lán)山咖啡', '123213');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • 解決PHP里大量數(shù)據(jù)循環(huán)時(shí)內(nèi)存耗盡的方法

    解決PHP里大量數(shù)據(jù)循環(huán)時(shí)內(nèi)存耗盡的方法

    錯(cuò)誤信息提示最大內(nèi)存已經(jīng)耗盡,該如何解決呢?下面小編給大家解決PHP里大量數(shù)據(jù)循環(huán)時(shí)內(nèi)存耗盡的問題,需要的朋友可以參考下
    2015-10-10
  • Zend Framework基本頁面布局分析

    Zend Framework基本頁面布局分析

    這篇文章主要介紹了Zend Framework基本頁面布局方法,結(jié)合實(shí)例形式分析了Zend Framework頁面布局的基本步驟與相關(guān)設(shè)置技巧,需要的朋友可以參考下
    2016-03-03
  • Yii2選項(xiàng)卡的簡(jiǎn)單使用

    Yii2選項(xiàng)卡的簡(jiǎn)單使用

    這篇文章主要為大家詳細(xì)介紹了Yii2選項(xiàng)卡的簡(jiǎn)單使用,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-05-05
  • ThinkPHP2.x防范XSS跨站攻擊的方法

    ThinkPHP2.x防范XSS跨站攻擊的方法

    這篇文章主要介紹了ThinkPHP2.x防范XSS跨站攻擊的方法,實(shí)例分析了ThinkPHP2.x針對(duì)XSS跨站攻擊的防范技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • PHP加MySQL消息隊(duì)列深入理解

    PHP加MySQL消息隊(duì)列深入理解

    這篇文章主要介紹了PHP+MySQL消息隊(duì)列深入理解,有感興趣的同學(xué)可以研究下
    2021-02-02
  • php實(shí)現(xiàn)的mongodb操作類

    php實(shí)現(xiàn)的mongodb操作類

    說到php連mongoDB,不得不先介紹一下php的官方手冊(cè),網(wǎng)址在:http://us.php.net/manual/en/book.mongo.php,接下來給大家分享一個(gè)本人常用的MONGODB的操作類,詳見的數(shù)據(jù)庫操作都有了,小伙伴可以參考下。
    2015-05-05
  • codeigniter中view通過循環(huán)顯示數(shù)組數(shù)據(jù)的方法

    codeigniter中view通過循環(huán)顯示數(shù)組數(shù)據(jù)的方法

    這篇文章主要介紹了codeigniter中view通過循環(huán)顯示數(shù)組數(shù)據(jù)的方法,實(shí)例分析了codeigniter中view方法與數(shù)組遍歷的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-03-03
  • PHP把網(wǎng)頁保存為word文件的三種方法

    PHP把網(wǎng)頁保存為word文件的三種方法

    最近工作遇到關(guān)于生成word的問題,現(xiàn)在總結(jié)一下生成word的三種方法的相關(guān)資料,需要的朋友可以參考下
    2014-04-04
  • 深入學(xué)習(xí)微信網(wǎng)址鏈接解封的防封原理visit_type

    深入學(xué)習(xí)微信網(wǎng)址鏈接解封的防封原理visit_type

    這篇文章主要介紹了深入學(xué)習(xí)微信網(wǎng)址鏈接解封的防封原理visit_type,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08
  • PHP+jQuery翻板抽獎(jiǎng)功能實(shí)現(xiàn)

    PHP+jQuery翻板抽獎(jiǎng)功能實(shí)現(xiàn)

    在電視節(jié)目中有一種抽獎(jiǎng)形式暫且叫做翻板抽獎(jiǎng),臺(tái)上有一個(gè)墻面,墻面放置幾個(gè)大方塊,主持人或者抽獎(jiǎng)?wù)叻_對(duì)應(yīng)的方塊即可揭曉中獎(jiǎng)結(jié)果。類似的抽獎(jiǎng)形式還可以應(yīng)用在WEB中,本文將使用PHP+jQuery為您講解如何實(shí)現(xiàn)翻板抽獎(jiǎng)程序。
    2015-10-10

最新評(píng)論