thinkphp关联模型的注意大小写

TP框架报错: thinkModel:relation方法不存在

首先检查大小写,尤其是模型名称首字母大写


/****
模型名字QqModel.class.php ******************************************************/
namespace HomeModel;             
use ThinkModelRelationModel;                   //命名空间不要写错
class QqModel extends RelationModel{              //继承自关系模型
    protected  $_link = array(
        'seller'=>array(                          //单个时可以随意写
          'mapping_type'=>self::BELONGS_TO,       //表的关系
          'foreign_key'=>'seller_id',             //要关联的表的
          'class_name'=>'seller',                 //要关联的表
          'as_fields'=>'name',                    //要在前台取出的数据,重要
        ),
    );
}

/**** 控制器名字IndexController.class.php ******************************************************/
public function index(){

$qq=D('qq'); //用大D函数实例化表


  $qqinfo=$qq->relation(true)->select();    //关联表要加入relation(true)
  $this->assign('qqinfo',$qqinfo);
  $this->display();
  }








原文地址:https://www.cnblogs.com/txxt/p/5693426.html