添加表单页面
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="__URL__/add" method="post">
<center>
<table border="1" bgcolor="#fff4ef" bordercolor="purple">
<tr>
<td>分类名称:<input type="text" name="name"></td>
</tr>
<tr>
<td>分类描述:<textarea name="fenlei" cols="30" rows="10"></textarea></td>
</tr>
<tr>
<td>品牌网址:<input type="text" name="wangzhi"></td>
</tr>
<tr>
<td><input type="submit" value="添加"></td>
</tr>
</form>
</center>
</body>
</html>
控制器页面 controller
<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Request;
class Index extends Controller
{
public function index()
{
return view();
}
//添加
public function add(){
$data=Request::instance()->param();
$res=model('studen')->add_one($data);
if(!$res){
$this->error('添加失败');
}
$this->success('添加成功','show');
}
}
实例化model层
<?php
namespace app\index\model;
use think\Model;
class Studen extends Model
{
public function add_one($data){
return $this->insert($data);
}
}