添加数据

(1)创建数据表:

CREATE TABLE IF NOT EXISTS `think_form` (

  `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,

  `title` varchar(255) NOT NULL,

  `content` varchar(255) NOT NULL,

  `create_time` int(11) unsigned NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

(2)创建模版:/App/Home/View/Form/add.html

<FORM method="post" action="__URL__/insert">

标题:<INPUT type="text" name="title"><br/>

内容:<TEXTAREA name="content" rows="5" cols="45"></TEXTAREA><br/>

<INPUT type="submit" value="提交">

</FORM>

(3)创建控制器:/App/Home/Controller/FormController.class.php

<?php

namespace HomeController;

use ThinkController;

class FormController extends Controller{

    public function insert(){

        $Form   =   D('Form');

        if($Form->create()) {

            $result =   $Form->add();

            if($result) {

                $this->success('操作成功!');

            }else{

                $this->error('写入错误!');

            }

        }else{

            $this->error($Form->getError());

        }

    }

}

(4)创建模型:/App/Home/Model/FormModel.class.php

<?php

namespace HomeModel;

use ThinkModel;

class FormModel extends Model {

    // 定义自动验证

    protected $_validate    =   array(

        array('title','require','标题必须'),

        );

    // 定义自动完成

    protected $_auto    =   array(

        array('create_time','time',1,'function'),

        );

}

(5)访问:http://127.0.0.1/index.php/Home/Form/add

相关文章

(1)创建数据表: CREATE TABLE IF NOT EXISTS `think_form` ...
组合查询的主体还是采用数组方式查询,只是加入了一些特殊的...
(1)创建模版:/App/Home/View/Form/edit.html   <FORM m...
自定义配置文件user.php: <?php return array(    \'se...
在一些成熟的CMS系统中,后台一般都包含一个配置中心(如织梦...
废话不多说先上图预览下,即本博客的分页; 这个分页类是在...