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
4.使用视图模型:
$rows = $Blog->where(array('cid'=>array('IN' , $cateList)))->select();
Thinkphp 视图模型的更多相关文章
- thinkphp 视图模型使用分析
<?php /** * 视图模型 * */ class ViewBatchModel extends ViewModel{ public $viewFields = array( 'Jinxia ...
- ThinkPHP 3.2.3 视图模型的使用
ThinkPHP 3.2.3 试图模型的手册地址是:http://www.kancloud.cn/manual/thinkphp/1781 实例 需求:在博客列表页读取博客的(id.标题.摘要.发布时 ...
- thinkphp 3.2 视图模型 实例 视图查询结果 二维数组 合并
使用视图模型查询的时候 结果是这样的 array(6) { [0] => array(5) { ["picTitle"] => string(7) "标题2& ...
- ThinkPHP中视图模型详解.
很多TP的新手对于模型中的视图模型不甚了解,官方虽然有详细手册,但是对于初学者来说还是比较难以理解! 先简单说一下视图模型所能实现的功能,基本就是主表与副表之间各个字段的关联问题,实现多表关联查询,相 ...
- ThinkPHP第十六天(redirect、join、视图模型)
1.redirect /** * Action跳转(URL重定向) 支持指定模块和延时跳转 * access protected * @param string $url 跳转的URL表达式 * @p ...
- ThinkPHP视图查询详解
ThinkPHP视图查询详解 参考http://www.jb51.net/article/51674.htm 这篇文章主要介绍了ThinkPHP视图查询,需要的朋友可以参考下 ThinkP ...
- thinkphp 视图定义
视图定义 视图通常是指数据库的视图,视图是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据.但是,视图并不在数据库中以存储的数据值集形式存在.行和列数据来自由定义视图的 ...
- 当类型为dynamic的视图模型遭遇匿名对象
当年在ASP.NET MVC 1.0时代我提到,在开发时最好将视图的Model定制为强类型的,这样可以充分利用静态检查功能进行排错.不过有人指出,这么做虽然易于静态检查,但是定义强类型的Model类型 ...
- [转]架构蓝图--软件架构 "4+1" 视图模型
架构蓝图--软件架构 "4+1" 视图模型 本文基于多个并发视图的使用情况来说明描述软件密集型系统架构的模型.使用多重视图允许独立地处理各"风险承担人":最终用 ...
随机推荐
- 栈 c实现
栈的数组实现 stack.h #ifndef _STACK_ #define _STACK_ #define SIZE 100 typedef int data_t; typedef struct h ...
- 【CSP】最大的矩形
问题描述 试题编号: 201312-3 试题名称: 最大的矩形 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ ...
- [LeetCode&Python] Problem 122. Best Time to Buy and Sell Stock II
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- Java中的Arrays类使用详解
首先先创建一个打印数组的方法,方便后面直接使用 public static void output(int []a) { for(int i=0;i<a.length;i++) { System ...
- (7)路由层的分发(不同app各自管理自己的和app的注册)
注意事项:新建的app一定要在settings.py中注册 app的注册 在这个位置进行注册 注册有两种方式: 1.'app01.apps.App01Config' #这个是标准的写法,官方推荐 ...
- c++期末考
1. 谁不及格? Problem:A Time Limit:1000ms Memory Limit:65535K Description 聪聪的班主任王老师最近有点忙,可是他又是一位非常细心的老师,每 ...
- 通过阻止 touchstart 事件,解决移动端的 BUG
在 iOS10 下,即使设置了 meta 标签的 user-scalable=no 依然不能阻止用户缩放. 解决此 BUG 的方法是阻止 PC 事件: document.addEventListene ...
- Go Example--值运算
package main import "fmt" //通过import导入fmt标准包 func main() { //+号可以用做连接字符串 fmt.Println(" ...
- BZOJ3730 震波 和 BZOJ4372 烁烁的游戏
"震波"题意 F.A.Qs Home Discuss ProblemSet Status Ranklist Contest 入门OJ ModifyUser autoint Log ...
- GoLand tool tips
goland format code (on save ) preference -> tool -> file watcher then ,select go fmt 2, highl ...