Home > Backend Development > PHP Tutorial > ThinkPHP automatic filling method to achieve unlimited classification, thinkphp filling_PHP tutorial

ThinkPHP automatic filling method to achieve unlimited classification, thinkphp filling_PHP tutorial

WBOY
Release: 2016-07-13 10:20:07
Original
787 people have browsed it

ThinkPHP automatic filling method to achieve unlimited classification, thinkphp filling

The example in this article shows how ThinkPHP auto-fills to achieve infinite classification. It is one of the common functions of ThinkPHP and is of great practical value. Now I will share the complete example with you for your reference. The specific implementation steps are as follows:

Table aoli_cate is shown below:

1. Action part:

aoli/Home/Lib/Action/CataAction.class.php file is as follows:

<&#63;php
class CateAction extends Action{
  function index(){
    $cate=M('cate');
    $list=$cate->field("id,name,pid,path,concat(path,'-',id) as bpath")->order('bpath')->select();
    foreach($list as $key=>$value){
       $list[$key]['count']=count(explode('-',$value['bpath']));
    }
    $this->assign('alist',$list);
    $this->display();  
  }
  //添加栏目
  function add(){
    $cate=new CateModel();
    
    if($vo=$cate->create()){
      if($cate->add()){
        $this->success('添加栏目成功');  
      }else{
        $this->error('添加栏目失败');  
      }
      //dump($vo);  
    }else{
      $this->error($cate->getError());  
    }
  }
  
}
&#63;>

Copy after login

2. Model part:

aoli/Home/Lib/Model/CataModel.class.php file is as follows:

<&#63;php
class CateModel extends Model{//对应数据库中的表aoli_cate
  protected $_auto=array(
    array('path','tclm',3,'callback'),  
  ); 
  
  function tclm(){
    $pid=isset($_POST['pid'])&#63;(int)$_POST['pid']:0;
    echo ($pid);
    if($pid==0){
      $data=0;
    }else{
      $list=$this->where("id=$pid")->find();
      $data=$list['path'].'-'.$list['id'];//子类的path为父类的path加上父类的id
    }
    return $data;  
  }
}
&#63;>

Copy after login

3. View part

aoli/Home/Tpl/default/Cate/index.html page is as follows:

<form action="__URL__/add" method="post">
 请选择父级栏目:<select name="pid" size="20">
         <option value="0">根栏目</option>
         <volist name="alist" id="vo">
          <option value="{$vo['id']}">
            <php>
              for($i=0;$i<$vo['count'];$i++){
                echo ' ';  
              }
            </php>
            {$vo['name']}
          </option>
         </volist>
        </select><br />
 新的栏目名称:<input type="text" name="name" /><br />
 <input type="submit" value="添加栏目" />
</form>

Copy after login

I believe that the examples described in this article have certain reference value for everyone’s ThinkPHP programming design.

thinkphp autofill problem

Silly bird, the last login time and last login IP need to be updated manually by writing a method. When verifying that the login is successful, call the update method you wrote.
The filling set by the Model is automatically filled when operating data.

You got the concept wrong.

php+mysql three-level classification, Li Wenkai thinkphp unlimited level classification

So, what do you want to ask?,,,, I have also watched this video, it’s pretty good,

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/868239.htmlTechArticleThinkPHP automatic filling method to achieve infinite classification, thinkphp filling The example of this article shows the method of ThinkPHP automatic filling to realize unlimited classification Method is one of the commonly used functions of ThinkPHP and is very useful...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template