入口文件 文件名 index.php
<?php
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
define('APP_DEBUG',True);
define('APP_PATH','./Message/');
require './ThinkPHP/ThinkPHP.php';
配置文件 文件名 config.php
<?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
<?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