1<?PHP2 3namespace Addons\vote\controller;//namespaces, setting voting vote4 5 UseHome\controller\addonscontroller;//introducing the system plug-in controller6 7 classVotecontrollerextendsAddonscontroller {//voting for the host controller8 protected $model;//set the field model9 protected $option;//set field optionTen Public function__construct () {//constructor Function OneParent::__construct ();//calling the constructor of the parent class A $this->model = M (' model ')->getbyname ($_request[' _controller ']);//Query the Model table for the plug-in basic list information - $this->model | |$this->error (' model does not exist! ‘ );//determine if the model exists, if there is no throw error hint - the $this->assign (' model ',$this->model);//upload model data to a template, the role of initialization - - $this->option = M (' Model ')->getbyname (' vote_option ');//Check vote_option Get voting model field information - $this->assign (' option ',$this->option);//option data is passed to the template, the role of initialization + } - /** + * Display the specified model list data A */ at Public functionLists () {//List control Methods - $page= I (' P ', 1, ' intval ');//show first page data by default - - //Parse list rule - $list _data=$this->_list_grid ($this->model);//_list_grid Method Parsing list rules - $grids=$list _data[' List_grids '];//to the sub-group name in $fields=$list _data[' Fields '];//to the sub-group name - to //Keyword search + $map[' token '] = Get_token ();//Get token - $key=$this->model [' Search_key ']?$this->model [' Search_key ']: ' title ';//judging and assigning values the if(isset($_request[$key] )) {//judging and converting characters to HTML entities * $map[$key] =Array ( $' Like ',Panax Notoginseng‘%‘ .Htmlspecialchars($_request[$key] ) . ‘%‘ - ); the unset($_request[$key] ); + } A //Conditional Search the foreach($_request as $name=$val) {//Loops + if(In_array($name,$fields)) {//assembling $map Arrays - $map[$name] =$val;//Pass the $val to $map [$name] $ } $ } - $row=Empty($this->model [' List_row '])? 20:$this->model [' List_row '];//determine and set model [' List_row '] - the //Read the model data list - Wuyi Empty($fields) ||In_array(' ID ',$fields) ||Array_push($fields, ' id ');//Judging fields in an array the $name= Parse_name (Get_table_name ($this->model [' id ']),true);//get the table name and convert the format - $data= M ($name)->field (Empty($fields) ?true:$fields)->where ($map)->order (' id DESC ')->page ($page,$row)->select ();//look up the table and sort the ID in ascending order Wu - /*Total Query Records*/ About $count= M ($name)->where ($map),Count (); $ - //page Out - if($count>$row) {//if the total is greater than the basic number of pages - $page=New\think\page ($count,$row);//Instantiation Sub-category A $page->setconfig (' theme ', '%first%%up_page%%link_page%%down_page%%end%%header% ' ); + $this->assign (' _page ',$page-Show ()); the } - $ $this->assign (' List_grids ',$grids);//Reference List_grids the $this->assign (' List_data ',$data);//Reference List_data the $this->meta_title =$this->model [' title ']. ' List ';//assigning values to Meta_title the $this->display (T (' Addons://[email protected]/lists '));//Call Template display the } - Public functionDel () {//Delete Methods in the list in $ids= I (' id ', 0);//assigning values to a parameter the if(Empty($ids)) {//determine if the $ids is empty the $ids=Array_unique( (Array) I (' IDs ', 0));//if $ids is not empty, the array is reduced to dimension About } the if(Empty($ids )) { the $this->error (' Please select data to manipulate! ');//if the array is empty, an error is indicated the } + - $Model= M (Get_table_name ($this->model [' ID ']));//instantiate a data for the corresponding ID in the model table the //Assemble an arrayBayi $map=Array ( the' id ' =Array ( the' In ', - $ids - ) the ); the $map[' token '] =Get_token (); the if($Model->where ($map)->delete ()) {//Delete data operation and make a decision whether to delete the success the $this->success (' Delete succeeded ' ); -}Else { the $this->error (' Delete failed! ‘ ); the } the}
Weiphp Voting Plugin's main controller section code