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

本文实例讲述了PHP实现的简单留言板功能。,具体如下:

入口文件  文件名 index.php

// 应用入口文件

// 检测PHP环境

if(version_compare(PHP_VERSION,'5.3.0',' 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),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

namespace HomeModel;

use ThinkModel;

class MsgModel extends Model{

//是否批量验证

protected $patchValidate = true;

protected $_validate = array(

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

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

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

);

protected $_auto = array (

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

array('id','NULL'),

array('admin_user','ms'),

array('replay','NULL'),

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

array('send_msg_time','time',3,'function'),

);

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值