thinkphp 留言板骨架

來源:互聯網
上載者:User

標籤: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>

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>

最後是資料庫設計以及資料庫設定代碼

資料庫設定代碼

<?phpreturn 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 留言板骨架

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.