ThinkPHP學習(三)

來源:互聯網
上載者:User

標籤:

我們已經將資料儲存到了後台資料庫,那接下來我們肯定要將資料顯示出來看看了。

先建立一個要顯示資料的模板formlist.html:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  <title>ThinkPHP</title> </head> <style type="text/css">table {    font-family: verdana,arial,sans-serif;    font-size:11px;    color:#333333;    border-width: 1px;    border-color: #666666;    border-collapse: collapse;    text-align: center;}table th {    border-width: 1px;    padding: 8px;    border-style: solid;    border-color: #666666;    background-color: #dedede;}table td {    border-width: 1px;    padding: 8px;    border-style: solid;    border-color: #666666;    background-color: #ffffff;} </style> <body> <div class="main"> <h2>你好</h2><table align=center><tr>    <th>主題</th><th>內容</th></tr><volist name="list" id="vo" empty="暫時沒有資料"><tr>    <td>{$vo.title}</td><td>{$vo.content}</td></tr></volist></table></div> </body></html>

然後在後台儲存成功後接著調用顯示:

<?phpclass IndexAction extends Action{        public function index(){        $hello=‘Hello,ThinkPHP !‘;        $this->assign(‘hello‘,$hello);        $this->display();    }    public function add(){        $form = M(‘Form‘);        $form->create();        $form->add();        $this->redirect(‘Index/formlist‘);    }    public function formlist(){        $form = M(‘Form‘);        $vo=$form->select();        $this->assign(‘list‘,$vo);        $this->display();    }}

對,就是簡單地修改一下add()方法,儲存成功後重新導向顯示模板,然後在formlist()中顯示出所有資料來。

注意方法名字和模板名字要匹配噢。

再試試儲存,儲存後會直接開啟顯示所有儲存結果的頁面。當然了,實際中不能這麼簡單地顯示所有資料。

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.