Thinkphp 视图模型
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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。