视图模型 先定义模型 再定义实体模型
http://doc.thinkphp.cn/manual/view_model.html
- class BlogViewModel extends ViewModel {
- public $viewFields = array(
- 'Blog'=>array('id','name','title'),
- 'Category'=>array('title'=>'category_name', '_on'=>'Blog.category_id=Category.id'),
- 'User'=>array('name'=>'username', '_on'=>'Blog.user_id=User.id'),
- );
- }
关联模型 定义关联
http://doc.thinkphp.cn/manual/relation_model.html
- class UserModel extends RelationModel{
- protected $_link = array(
- 'Profile'=>array(
- 'mapping_type' =>HAS_ONE,
- 'class_name' =>'Profile',
- // 定义更多的关联属性
- ……
- ),
- );
- }