Add new product category

New product category

CateController.class.php controller

<?php
namespace Admin\Controller;
use Think\Controller;
class CateController extends  CommonController
{
    public function index(){

        $this->display();
    }
     public function add(){
        $cate=D('Cate');
        if (IS_POST) {
            if($cate->create()){
                if ($cate->add()) {
                    $this->success('添加商品分类成功',U('Cate/add'));
                }else{
                    $this->error('添加商品分类失败!');
                }
            }else{
                $this->error($cate->getError());
            }
            return;
        }
        $cateres=$cate->select();
        $this->assign('cateres',$cateres);
        $this->display();
    }

}

CommonController continues to inherit the public controller

$cateres=$cate->select();
$this->assign('cateres',$cateres);

assigned to the template category.

QQ截图20170623115112.png

##CateModel.class.php

<?php
namespace Admin\Model;
use Think\Model;
class CateModel extends Model {
    protected $_validate = array(
      array('catename','require','管理员名称不得为空!',1),
    );

}

Add classification attempt

QQ截图20170623112918.png

QQ截图20170623112950.png

QQ截图20170623115101.png

Submit without adding a name

QQ截图20170623113116.png

Verification takes effect


##

Continuing Learning
||
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>PHP</title>
<meta name="description" content="Dashboard">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--Basic Styles-->
<link href="__PUBLIC__/style/bootstrap.css" rel="stylesheet">
<link href="__PUBLIC__/style/font-awesome.css" rel="stylesheet">
<link href="__PUBLIC__/style/weather-icons.css" rel="stylesheet">
<!--Beyond styles-->
<link id="beyond-link" href="__PUBLIC__/style/beyond.css" rel="stylesheet" type="text/css">
<link href="__PUBLIC__/style/demo.css" rel="stylesheet">
<link href="__PUBLIC__/style/typicons.css" rel="stylesheet">
<link href="__PUBLIC__/style/animate.css" rel="stylesheet">
</head>
<body>
<!-- -->
<include file="Common/header" />
<!-- / -->
<div class="main-container container-fluid">
<div class="page-container">
<!-- Page Sidebar -->
<include file="Common/left" />
<!-- /Page Sidebar -->
<!-- Page Content -->
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
submitReset Code
图片放大关闭