码迷,mamicode.com
首页 > Web开发 > 详细

Thinkphp 视图模型

时间:2015-02-16 14:15:36      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:

1.创建视图模型

2.定义视图模型

class BlogViewModel extends ViewModel {
   public $viewFields = array(
     ‘Blog‘=>array(‘id‘,‘name‘,‘title‘),
     ‘Category‘=>array(‘title‘=>‘category_name‘,‘_on‘=>‘Category.id=Blog.category_id‘,‘_type‘=>‘RIGHT‘),
     ‘User‘=>array(‘name‘=>‘username‘, ‘_on‘=>‘Blog.user_id=User.id‘),
   );
 }

3.数据库语句:

Select 
 Blog.id as id,
 Blog.name as name,
 Blog.title as title,
Category.title
as category_name,
User.name as username
from think_blog Blog JOIN think_category Category JOIN think_user User where Blog.category_id=Category.id AND Blog.user_id=User.id

 

Thinkphp 视图模型

标签:

原文地址:http://www.cnblogs.com/subtract/p/4294004.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!