table=D("CatField"); //字段类型 $this->fieldtype_inc=array( "varchar"=> "字符型0-255字节(varchar)", "char"=> "定长字符型0-255字节(char)", "text"=> "小型字符型(text)", "mediumtext"=> "中型字符型(mediumtext)", "longtext"=> "大型字符型(longtext)", "tinyint"=> "小数值型(tinyint)", "smallint"=> "中数值型(smallint)", "int"=> "大数值型(int)", "bigint"=> "超大数值型(bigint)", "float"=> "数值浮点型(float)", "double"=> "数值双精度型(double)", "date"=> "日期型(date)", "datetime"=> "日期时间型(datetime)", ); //表单类型 $this->formtype_inc=array( "text"=> "单行文本框(text)", "password"=> "密码框(password)", "select"=> "下拉框(select)", "radio"=> "单选框(radio)", "checkbox"=> "复选框(checkbox)", "textarea"=> "多行文本框(textarea)", "editor"=> "编辑器(editor)", "image"=> "图片(image)", "morepic"=> "多图上传(morepic)", "file"=> "文件(file)", "video"=> "视频(video)", "date"=> "日期(date)", "baidumap"=> "百度地图(map)", ); //常用正则 $this->pattern_inc=array( "/^[0-9.-]+$/"=> "数字", "/^[0-9-]+$/"=> "整数", "/^[1-9]\d*$/"=> "大于0", "/^[a-z]+$/i"=> "字母", "/^[0-9a-z]+$/i"=> "数字+字母", "/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/"=> "E-mail", "/^[0-9]{5,20}$/"=> "QQ", "/^http:\/\//"=> "超级链接", "/^(1)[0-9]{10}$/"=> "手机号码", "/^[0-9-]{6,13}$/"=> "电话号码", ); //系统字段(禁止删除) $this->systemfield_inc=array("name","classpath","thumb","lencord","is_page","listtemp","viewtemp","status","pagetitle","keywords","description"); } public function index(){ $data=$this->table->where(array("table_id"=>$this->table_id))->order('sort asc,field_id asc')->select(); $this->tableName=M("table")->where(array("table_id"=>$this->table_id))->getField("table_name"); $this->assign("data",$data); $this->display(); } public function add(){ if(IS_POST){ if (!$this->table->create()){//验证 $this->error($this->table->getError()); } $result=$this->table->data_add(); if(!$result){ $this->error($this->table->getError()); } D("UserLog")->add("add",$this->table->getTableName(),$result); $this->success($result); }else{ $this->display(); } } public function editor(){ if(IS_POST){ if (!$this->table->create()){//验证 $this->error($this->table->getError()); } $result=$this->table->data_editor(); D("UserLog")->add("update",$this->table->getTableName(),$result[field_id]); if(!$result){ $this->error($this->table->getError()); } $this->success($data); }else{ $field_id=I("get.field_id",0,"int"); $r=$this->table->find($field_id); $this->assign("r",$r); $this->display(); } } //删除 public function delete(){ $field_id=I("field_id",0,'intval'); $result=$this->table->data_delete($field_id,$this->systemfield_inc); D("UserLog")->add("delete",$this->table->getTableName(),$field_id); if(!$result){ $this->error($this->table->getError()); } $this->success("删除成功"); } //字段排序 public function sort(){ $filed_id=I("filed_id"); $sort=I("sort"); foreach($filed_id as $key=>$id){ $data['field_id']=(int)$id; $data['sort']=(int)$sort[$key]; $this->table->save($data); } $this->success("排序更改成功"); } }