加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

PHP实现的简单留言板功能示例【基于thinkPHP框架】

发布时间:2020-12-14 13:57:37 所属栏目:大数据 来源:网络整理
导读:本篇章节讲解PHP实现的简单留言板功能。供大家参考研究具体如下: 入口文件 文件名 index.php // 应用入口文件 // 检测PHP环境 if(version_compare(PHP_VERSION,'5.3.0',' 5.3.0 !'); // 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false

本篇章节讲解PHP实现的简单留言板功能。分享给大家供大家参考,具体如下:

入口文件 文件名 index.php

// 应用入口文件

// 检测PHP环境

if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');

// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false

define('APP_DEBUG',True);//开发调试模式

//define('APP_DEBUG',false);//生产模式

// 定义应用目录

define('APP_PATH','./Message/');

// 引入ThinkPHP入口文件

require './ThinkPHP/ThinkPHP.php';

// 亲^_^ 后面不需要任何代码了 就是如此简单

配置文件 文件名 config.php

return array(

//'配置项'=>'配置值'

'SHOW_PAGE_TRACE'=>true,

'DB_TYPE' => 'mysqli',// 数据库类型

'DB_HOST' => '127.0.0.1',// 服务器地址

'DB_NAME' => 'msg',// 数据库名

'DB_USER' => 'root',// 用户名

'DB_PWD' => 'root',// 密码

'DB_PORT' => '3306',// 端口

'DB_PREFIX' => 'ms_',// 数据库表前缀

);

控制器 文件名 MsgController.class.php

namespace HomeController;

use ThinkController;

use ThinkModel;

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 HomeModelMsgModel();

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),'修改失败');

}

}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','添加成功');

}else{

$this->redirect('addMsg','添加失败');

}

}else{

$this->display();

}

}

public function del($id){

if(D('Msg')->delete($id)){

$this->success('成功',U('index'),2);

}else{

$this->error('失败',2);

}

}

}

模板 文件名 MsgModel.class.php

namespace HomeModel;

use ThinkModel;

class MsgModel extends Model{

//是否批量验证

protected $patchValidate = true;

protected $_validate = array(

array('title','require','标题不能为空!'),//默认情况下用正则进行验证

array('user','留言人不能为空!'),

array('msg','内容不能为空!'),

);

protected $_auto = array (

array('status','1'),// 新增的时候把status字段设置为1

array('id','NULL'),

array('admin_user','ms'),

array('replay',

array('update_time','time',3,'function'),// 对update_time字段在更新的时候写入当前时间戳

array('send_msg_time',

);

}

视图 文件名 addMsg.html

Title

视图 文件名 index.html

留言列表 -- HoverTree

留言列表

视图 文件名 sendMsg.html

Title

标题:

信息:

留言人:

视图 文件名 upd.html

Title

目录结构

数据库 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`

--

-- --------------------------------------------------------

--

-- 表的??? `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 '更新时间',

`status` int(2) NOT NULL COMMENT '状态',

`send_msg_time` int(10) NOT NULL COMMENT '留言时间',

`user` varchar(100) NOT NULL COMMENT '留言人',

`title` varchar(100) NOT NULL COMMENT '标题',

`msg` varchar(200) NOT NULL COMMENT '内容',

`replay` varchar(200) NOT NULL COMMENT '回复',

PRIMARY KEY (`id`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='留言表' AUTO_INCREMENT=19 ;

--

-- ?存?料表中的?料 `ms_msg`

--

INSERT INTO `ms_msg` (`id`,`admin_user`,`update_time`,`status`,`send_msg_time`,`user`,`title`,`msg`,`replay`) VALUES

(1,'ms',1479449110,1,'1','拉克丝的减肥','对方科目了',

(7,'',321423432,'kljflwk','kjsdfnlk','nlkdsjfn','kljnf'),

(3,1479451017,'轻松的发生我','沃尔沃飞',

(8,1479544687,'qwe',

(9,1479544693,

(10,1479544970,

(11,1479544979,'12',

(12,1479545029,

(13,1479546357,

(14,1479547163,

(16,1479547667,'123',

(17,2147483647,1479547682,'上来昆明3','说的了付款','蓝山咖啡','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 */;

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!