Home >Backend Development >PHP Tutorial >thinkphp自带的分表 老是找不到表名 大神帮忙看看

thinkphp自带的分表 老是找不到表名 大神帮忙看看

WBOY
WBOYOriginal
2016-06-06 20:23:211316browse

<code>模型中

namespace Home\Model;
use Think\Model;


class FollowModel extends AdvModel{
    //分表方式
    protected $partition = array('field'=>'vid','type'=>'mod','num'=>'2');
    
    //获取操作表名
    public function getDao($data=array()) {
//           $data = empty($data) ? $_POST : $data;
          $table = $this->getPartitionTableName($data);
           return $this->table($table);
    }
    
}

方法中
namespace Home\Controller;
use Think\Controller;

class ActionController extends Controller {
    
    public function Test() {
        //获取分表
        $soft_tj_table = D("Follow")->getDao(array('vid'=>5));
        dump($soft_tj_table);
    }
    
}

由于使用了高级模型  返回的表名老是报错 $table 
</code>

回复内容:

<code>模型中

namespace Home\Model;
use Think\Model;


class FollowModel extends AdvModel{
    //分表方式
    protected $partition = array('field'=>'vid','type'=>'mod','num'=>'2');
    
    //获取操作表名
    public function getDao($data=array()) {
//           $data = empty($data) ? $_POST : $data;
          $table = $this->getPartitionTableName($data);
           return $this->table($table);
    }
    
}

方法中
namespace Home\Controller;
use Think\Controller;

class ActionController extends Controller {
    
    public function Test() {
        //获取分表
        $soft_tj_table = D("Follow")->getDao(array('vid'=>5));
        dump($soft_tj_table);
    }
    
}

由于使用了高级模型  返回的表名老是报错 $table 
</code>

命名空间不正确

<code>use Think\Model\AdvModel;</code>
Statement:
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