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.
##CateModel.class.php
<?php namespace Admin\Model; use Think\Model; class CateModel extends Model { protected $_validate = array( array('catename','require','管理员名称不得为空!',1), ); }Add classification attempt
Submit without adding a name
Verification takes effect