1、第一个问题:
分类表cate关联文章内容表content(一对多关联 HAS_MANY)。
设置了'as_fields'=>'ti
CateModel 模型类:
<?php
namespace Home\Model;
use Think\Model;
use Think\Model\RelationModel;
class CateModel extends RelationModel{
//关联content表
protected $_li
'content'=>array(
'mapping_type'=>self::HAS_MANY, //一对多关联
'foreign_key'=>'cid', //通过关联表字段相关联
'mapping_fields'=>'ti
'as_fields'=>'ti
),
);
}
打印出数组:
Array
(
[0] => Array
(
[id] => 1
[name] => 巨人
[pid] => 0
[sort] => 100
[content] => Array
(
[0] => Array
(
[ti
)
)
)
-----------------------分界线---------------------------
2、第二个问题:
文章内容表content关联分类表cate(多对一关联 BELONGS_TO)。
ContentModel模型类:
<?php
namespace Home\Model;
use Think\Model;
use Think\Model\RelationModel;
class ContentModel extends RelationModel{
protected $_li
'cate'=>array(
'mapping_type'=>self::BELONGS_TO, //多对一关联
'foreign_key'=>'pid', //通过关联表字段相关联
),
);
}
问题以下报错:
:(
Think\Model:relation方法不存在!
错误位置
FILE: D:\wamp\www\think\ThinkPHP\Library\Think\Model.class.php LINE: 226
最佳答案