ThinkPHP3.2.3快速入門(建立資料)
阿新 • • 發佈:2019-02-18
一.準備工作
- 開發環境整合工具:phpstudy,thinkphp3.2.3
- 將thinkphp3.2.3放在WWW目錄下,在phpstudy域名管理中配置域名www.thinkphp323.com,
- 在hosts中新增127.0.0.1 www.thinkphp323.com,
- 在瀏覽器中訪問將會看到如下:
二.建立資料
控制器
模型
(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>