
分类表

NewsModel.class.php
<?php
class NewsModel extends RelationModel
{
protected $_link = array(
'news_category'=> array(
'mapping_type'=>BELONGS_TO,
'class_name'=>'news_category',
'foreign_key'=>'cat_id',
'mapping_limit'=>10,
'mapping_name'=>'news_category',
'as_fields'=>'cat_name'//查询字段
)
);
}
?>IndexAction.class.phpclass IndexAction extends Action {
public function index(){
$re = D('News');
$categorylist=$re->relation(true)->field('title')->limit(10)->select();
print_r($categorylist);
$this->display();
}
}我要查出新闻的ti但是cat_name为空?
最佳答案