thinkphp323/index.php/home/Form/add public function insert(){

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 ;

 

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\View\Form\add.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> __URL__ </title>
  <meta charset="UTF-8">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>

 <body>
<!--
action="/thinkphp323/index.php/Home/Form/insert"
-->
<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>

 </body>
</html>

D:\LearnWebDevelop\php\thinkphp_3.2.3_full\Application\Home\Controller\FormController.class.php

<?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{
           //下面是一个标准的URL访问格式:
           //http://serverName/index.php/模块/控制器/操作(/参数名/参数值)
//http://localhost/thinkphp323/index.php/home/Form/add
//http://localhost/thinkphp323/index.php/home/index/hello/name/baby

    //public function add(){
        //$Data = M('Data');// 实例化Data数据模型
        //var_dump($Data);exit();
        //$result = $Data->find(1);
    //    $this->assign('title',"Form/add");
    //    $this->display();
    //}

    public function insert(){
        //var_dump($_POST);

        $Form = D('Form');
        if($Form->create()) {
            $result = $Form->add();
            if($result) {
                $this->success('数据添加成功!');
            }else{
                $this->error('数据添加错误!');
            }
        }else{
            $this->error($Form->getError());
        }

        //$this->assign('result',"Success!");
        //$this->display();

    }

}

 

posted @ 2017-11-24 15:01  sky20080101  阅读(96)  评论(0)    收藏  举报