[php]代码库
<?php
class MessageModel extends RelationModel{
protected $_auto=array(
array('time','time',1,'function'), //自动填充
array('uid','getId',1,'callback')
);
protected $_link=array(
'User'=> array(
'mapping_type'=>BELONGS_TO,
'class_name'=>'User',
'foreign_key'=>'uid',
'mapping_name'=>'user',
'mapping_fields'=>'username',
'as_fields'=>'username:uname',//变为评级状态字段冲突可改 必解继承RelationModel
),
);
protected function getId(){
return $_SESSION['id'];
}
}
?>
//自动填充的功能
//$message->time=time();
//$message->uid=$_SESSION['id'];
自动获取值
//关联查询时用relation(true)
$arr=$message->relation(true)->limit($page->firstRow.','.$page->listRows)->select();