ThinkPHP3.2.3快速入门(创建数据)

一.准备工作

  1. 开发环境集成工具:phpstudy,thinkphp3.2.3
  2. 将thinkphp3.2.3放在WWW目录下,在phpstudy域名管理中配置域名www.thinkphp323.com,
  3. 在hosts中添加127.0.0.1 www.thinkphp323.com,
  4. 在浏览器中访问将会看到如下:

这里写图片描述

二.创建数据

  • 控制器

  • 模型

    (1)创建数据库thinkphp323和数据表think_form

create database thinkphp323;
use thinkphp323;
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)在/Application/Home/Conf/config.php中配置数据库信息

<?php
return array(
    //'配置项'=>'配置值'
    'DB_TYPE'=> 'mysql',          // 数据库类型
    'DB_HOST'=> 'localhost', // 数据库服务器地址
    'DB_NAME'=>'thinkphp323',  // 数据库名称
    'DB_USER'=>'root', // 数据库用户名
    'DB_PWD'=>'root', // 数据库密码
    'DB_PORT'=>'3306', // 数据库端口
    'DB_PREFIX'=>'think_', // 数据表前缀
    'DB_CASE_LOWER'=>true,
);

(3) 在/Application/Home/Model下创建模型类FormModel.class.php

<?php
namespace Home\Model;
use Think\Model;
class FormModel extends Model {
    // 定义自动验证
    protected $_validate = array(
        array('title','require','不能为空'),

    );
    // 定义自动完成
    protected $_auto = array(
    array('create_time','time',1,'function'),
    );
}
  • 视图
<form action="__URL__/insert" class="form" method="post">
      <div class="form-group">
           <label for="title">标题</label>
           <input type="password" class="form-control" id="title" placeholder="请输入标题">

       <div class="form-group">
       <label for="">内容</label>
       <textarea class="form-control" rows="6"></textarea>
       <button type="submit" class="btn btn-primary tj">提交</button>
 </form>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章