本文实例讲述了服务器端编程语言(专业超文本预处理器的缩写)实现的简单留言板功能。分享给大家供大家参考,具体如下:
入口文件文件名index.php
?php/应用入口文件//检测服务器端编程语言(专业超文本预处理器的缩写)环境if(version_compare(PHP_VERSION,' 5.3.0 ',' ')die('要求PHP 5.3.0!');//开启调试模式建议开发阶段开启部署阶段注释或者设为falsedefine('APP_DEBUG ',True);//开发调试模式//define('APP_DEBUG ',false);//生产模式//定义应用目录定义(' APP_PATH ',' ./Message/');//引入ThinkPHP入口文件要求/ThinkPhp/ThinkPhp。PHP ';//亲^_^ 后面不需要任何代码了就是如此简单配置文件文件名config.php
?phpreturn数组(//'配置项'='配置值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
?phpnamespace主页控制器;使用思考控制器;使用思考模型;类msgccontroller扩展了控制器{公共函数索引(){ $ Msg=D(' Msg ');$ info=$ msg-order(' id desc ')-select();$this-assign('info ',$ info);$ this-display();}公共函数发送消息(){ $ msg=new Home Model msg Model();if(!空($ _ POST)){ $ data=$ msg-create();if($ data){ $ data[' user _ hobby ']=inter decd(',',$ data[' user _ hobby ']);$ z=$ msg-add($ data);if($ z){ $ this-redirect(' Msg/SendMsg ');} }else{ $this-assign('errorInfo ',$ msg-GetError());} } $ this-display();}公共函数upd($ id){ $ Msg=D(' Msg ');if(!空($ _ 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();} }公共函数addMSg(){ $ MSg=D(' MSg ');if(!空($ _ POST)){ $ z=$ msg-add($ _ POST);if ($z){ $this-redirect('index ',array(),2,'添加成功');}else{ $this-redirect('addMsg ',数组(),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
?phpnamespace主页模型使用思考模型;类MsgModel扩展了型号{ //是否批量验证受保护的$ patchValidate=true受保护的$_validate=array(array('title ',' require ','标题不能为空!'), //默认情况下用正则进行验证数组(“用户”,“要求”,留言人不能为空!'),数组(“消息”,“要求”,内容不能为空!'), );受保护的$_auto=array (array('status ',' 1 '),//新增的时候把状态字段设置为一数组(' id ',' NULL '),数组(' admin_user ',' ms '),数组(“重播”、“空”),数组(“update_time”,“time”,3,“function”),//对更新时间字段在更新的时候写入当前时间戳数组(' send_msg_time ',' time ',3,' function ',);}视图文件名addMsg.html
!DOCTYPE html html lang=' en ' head meta charset=' UTF-8 ' title/title/head dydiv form action=' _ _ SELF _ _ ' method=' post ' table border=' 1 ' width=' 100% ' class=' table _ a ' tr TD留言时间/TD tdinput type=' text ' name=' update _ time '/TD/tr tr TD留言人TD/TD输入类型=“文本”名称='用户'/TD/tr TD标题/TD TD输入类型=' text '名称=' title '/TD/tr/tr TD内容/TD TD输入类型=' text '名称=' msg '/TD/tr TD回复/TD tdtextarea name=' replay '/textarea/TD/tr TD colspan=' 2 ' align=' center '输入类型='submit '值='添加a href=' _ _ CONtrol _ _/index ' rel='外部不跟随' rel='外部不跟随'输入类型='按钮'值='返回/a/TD/tr/table/form/div/body/html视图文件名index.html
!DOCTYPE html html xmlns=' http://www .w3。org/1999/XHTML '标题留言列表-悬停树/标题样式. keleyitable { width: 800px }。凯莱宜表,td,th { border: 1px实心绿色;页边距-top :10 px;} .kly TD { width :100 pxtext-align : right } .hvttd { width :500 px }/style/headdydiv style=' margin 3 33600 px auto;class=' keleyitable ' h2留言列表/H2 trtd class=' kly TD ' a href=' _ _ CONtrol _ _/AddMSg ' rel='外部无跟随'添加/a/tdtd class=' hvttd '/TD/tr volist name=' info ' id=' VO ' table trtd class=' klytd '留言时间:/tdtd class=' hvttd '“$ VO。update _ time | date=' Y-m-d h : I :s ',##}/td/tr trtd class='klytd '留言人:/tdtd class=' HV ttd '($ VO。用户}/TD/tr trtd class=' kly TD '标题:/tdtd class=' HV ttd '($ VO。标题}/TD/tr trtd class=' kly TD '内容:/tdtd class=' HV ttd '($ VO。msg }/TD/tr trtd class=' kly TD '回复:/tdtd class=' HV ttd '($ VO。replay }/TD/tr/table trtd class=' kly TD ' a href=' _ _ COMMERCE _ _/upd/id/{ $ VO。id } ' rel='外部无跟随'修改/a/tdtd class=' hvt TD '/TD/tr trtd class=' kly TD ' a href=' _ _ URL _ _/del/id/{ $ VO。id } ' rel='外部无跟随'删除/a/tdtd class=' hvt TD '/TD/tr/volist/div style=' width :800 px;margin:10px汽车;字体系列Helvetica阿里亚尔:无衬线;文本对齐:居中;气垫树2014年keleyi.com/div!-最近打算开发一个留言板,asp.net的开源项目,http://气垫树. codeplex.com-/正文/html视图文件名sendMsg.html
!DOCTYPE html html lang=' en ' head meta charset=' UTF-8 ' title/title/head body form action=' method=' post '标题:输入类型=' text ' name=' title ' span style=' color : red;{ $ ErrorInfo。title }/spanbr信息:输入类型=' text ' name=' msg ' span style=' color : red;{$errorInfo.msg}/spanbrbr留言人:输入类型=“文本”名称=' user ' span style=' color : red;'{ $ ErrorInfo。用户}/spanbbr输入类型='提交'值='提交/表单/正文/html视图文件名upd.html
!DOCTYPE html html lang=' en ' head meta charset=' UTF-8 ' title/title/head dydiv form action=' _ _ SELF _ _ ' method=' post ' input type=' hidden ' name=' id ' value=' { $ info。id } '表格边框=' 1 '宽度=' 100% ' class=' table _ a ' tr TD留言时间/TD TD input type=' text ' name=' update _ time ' value=' { $ info。update _ time } '//TD/tr TD留言人/TD TD TD input type=' text ' name=' user ' value=' { $ info。用户} '//TD/tr tr TD标题/TD TD TD input type=' text ' name=' title ' value=' { $ info。标题} '//TD/tr tr TD内容/TD TD input type=' text ' name=' msg ' value=' { $ info。msg } '//TD/tr tr TD回复/TD tdtextarea name=' replay ' ($ info。replay }/text area/TD/tr TD col span=' 2 ' align=' center '输入类型='submit '值='修改a href=' _ _ CONtrol _ _/index ' rel='外部不跟随' rel='外部不跟随'输入类型='按钮'值='返回/a/TD/tr/table/form/div/body/html目录结构
数据库结构化查询语言语句
设置' SQL_MODE='否_自动_值_开_零;设置时区=' 00:00 ';/*!40101 SET @[电子邮件保护]@ CHARACTER _ SET _ CLIENT */;/*!40101 SET @[电子邮件保护]@ CHARACTER _ SET _ RESULTS */;/*!40101 SET @[电子邮件保护]@ COORTION _ CONNECTION */;/*!40101 SET NAMES utf8 */;-資料庫: `msg` -表的結構` ms_msg` -如果不存在则创建表格` ms _ msg `(` id ' int(10)NOT NULL AUTO _ INCREMENT COMMENT '主键,` admin_user` varchar(100)非空注释'管理员、“更新时间”int(10)非空注释更新时间、"状态int(2)非空注释"状态,` send _ msg _ time ` int(10)非空注释'留言时间、"用户" varchar(100)非空注释留言人,` title` varchar(100)非空注释'标题、` msg` varchar(200)非空注释'内容、"重放“瓦尔查尔(200)非空注释回复,PRIMAry KEY(` id `)ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='留言表自动增量=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,1479449110,' 1 ','拉克丝的减肥', '对方科目了,' NULL '),(7 ' ',321423432,0,0,' kljflwk ',' kjsdfnlk ',' nlkdsjfn ',' kljnf ',(3,' ms ',1479451017,1,1479451017,' 1 ','轻松的发生我', '沃尔沃飞,' NULL '),(8,' ms ',1479544687,1,1479544687 '',' qwe ',' ',' NULL '),(9,' ms ',1479544693,1,14795444693,' qwe ',' qwe ',' qwe ',' NULL '),(10,' ms ',1479544970,1,1479544970,' qwe ',' qwe ',' qwe ','上来昆明3', '说的了付款', '蓝山咖啡', '123213'); /*!40101 SET[电子邮件保护]_ CHARACTER _ SET _ CLIENT */;/*!40101 SET[电子邮件保护]_ CHARACTER _ SET _ RESULTS */;/*!40101 SET[电子邮件受保护]_ COORTION _ CONNECTION */;更多关于框架相关内容感兴趣的读者可查看本站专题: 《ThinkPHP入门教程》 、 《thinkPHP模板操作技巧总结》 、 《ThinkPHP常用方法总结》 、 《codeigniter入门教程》 、 《CI(CodeIgniter)框架进阶教程》 、 《Zend FrameWork框架入门教程》 及《PHP模板技术总结》 。
希望本文所述对大家基于ThinkPHP框架的服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。