码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp 留言板骨架

时间:2014-12-03 20:56:53      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

显示页代码

<form action="/lyb/index.php/Index/insert.html" method="post">
<input name="text" type="text" value="表单提交" />
<input name="aaa" type="submit" />
</form>

bubuko.com,布布扣

action地址要换成thinkphp里的u方法,也就是去控制器里找方法,这个方法负责接收post来的数据,并把数据添加到数据库

控制器代码

<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
    public function index(){

    $this->display();
    }


public function insert(){
header("Content-Type:text/html; charset=utf-8");
$Text=$_POST[‘text‘];
    $Dao = M("Ly");    // 实例化模型类
    $list = $Dao->select();
    // 构建写入的数据数组
    $data["content"] = $Text;
if($lastInsId = $Dao->add($data)){
        echo "插入数据 id 为:$lastInsId";
    } else {
        $this->error(‘数据写入错误!‘);
    }
    dump($Text);
$this->assign(‘div‘,$list);
    $this->display(‘index‘);
    }
}



 

页面显示代码

<form action="{:U(‘Index/insert‘)}" method="post">
<input name="text" type="text" value="表单提交" />
<input name="aaa" type="submit" />
</form>

<foreach name="div" item="vo">
<div style="background-color:#FF8F59;onclick="window.open">           
 {$vo.content}
</div>     
 </foreach>

最后是数据库设计以及数据库设置代码

bubuko.com,布布扣

数据库设置代码

<?php
return array(
    //‘配置项‘=>‘配置值‘
    //‘USERNAME‘=>‘admin‘, //赋值
    //数据库配置信息
        ‘DB_TYPE‘   => ‘mysql‘, // 数据库类型
        ‘DB_HOST‘   => ‘localhost‘, // 服务器地址
        ‘DB_NAME‘   => ‘lyb‘, // 数据库名
        ‘DB_USER‘   => ‘root‘, // 用户名
        ‘DB_PWD‘    => ‘root‘, // 密码
        ‘DB_PORT‘   => 3306, // 端口
        ‘DB_PREFIX‘ => ‘xp_‘, // 数据库表前缀 
        //其他项目配置参数
        // ...
);
?>

 http://url.cn/dmfB8I

thinkphp 留言板骨架

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/hellowzd/p/4140963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!