cakephp之查询
find public
find( string $type 'first' , array $query array() )
Queries the datasource and returns a result set array.
Also used to perform notation finds, where the first argument is type of find operation to perform (all / first / count / neighbors / list / threaded), second parameter options for finding ( indexed array, including: 'conditions', 'limit', 'recursive', 'page', 'fields', 'offset', 'order')
Eg:
find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'fields' => array('name', 'email'),
'order' => 'field3 DESC',
'recursive' => 2,
'group' => 'type'
));
In addition to the standard query keys above, you can provide Datasource, and behavior specific keys. For example, when using a SQL based datasource you can use the joins key to specify additional joins that should be part of the query.
find('all', array(
'conditions' => array('name' => 'Thomas Anderson'),
'joins' => array(
array(
'alias' => 'Thought',
'table' => 'thoughts',
'type' => 'LEFT',
'conditions' => '`Thought`.`person_id` = `Person`.`id`'
)
)
));
代码示例:
$pv_count = $this->page_visit->findCount("page_visit.session_id='{$_session_id}' and page_visit.ip='{$ip}' and page_visit.url='{$_url}'");
$time = time();
$pv_new_insert = true;
if ($pv_count > 0) {
$pv = $this->page_visit->find('all', array(
'conditions' => array('session_id' => $_session_id, 'ip'=>$ip, 'url'=>$_url),
'fields' => array('*'),
'order' => 'time_start DESC',
'limit'=>1
));
$obj = $pv[0]["page_visit"];
$old_time_start = intval($obj['time_start']);
$sux = $time - $old_time_start;
$interval = $time - $pv['time_start'];
if ($sux > 3600) {
//超过一个小时后就算是新的访问记录
} else {
//一小时之内的刷新页面,只更新记录的更改时间
$pv_new_insert = false;
$obj['updated'] = $time;
$this->page_visit->save($obj);
}
}
if ($pv_new_insert) {//新增用户访问页面的记录
$pageVisit = Array();
$pageVisit['session_id'] = $_session_id;
$pageVisit['ip'] = $this->User->getip();
$pageVisit['url'] = $_url;
$pageVisit['time_start'] = $time;
$pageVisit['created'] = $time;
$pageVisit['updated'] = $time;
$pageVisit['device'] = $device . $_SERVER['HTTP_USER_AGENT'];
$this->page_visit->save($pageVisit);
}
cakephp之查询的更多相关文章
- cakephp 复杂查询
$now = time(); $this->CardTypeInfos->recursive = -1; $conditions = [ 'seller_id'=>SELLER_ID ...
- CakePHP采用model的save方法更新数据所需查询
采用model的save方法更新数据所需查询 1. 验证时候要确认是update 或者 create,以便使用对应规则 public $validate = array( 'field_name' = ...
- cakephp中sql查询between
$trading_list = $this->Trading->find('all', array('conditions' => array('buy_time BETWEEN ? ...
- CakePHP 查询总结
返回 $this->Post->buildQuery(); 返回: Array ( [conditions] => [fields] => [joins] => Arra ...
- cakephp中sql查询in
$list = $this->Capital->find('all', array('conditions'=>array('remark in '=>array('银联支付' ...
- cakephp中sql查询大于
$list = $this->Capital->find('all', array('conditions'=>array('amount >'=>0)));
- CakePHP之请求与响应对象
请求与响应对象 请求与响应对象在 CakePHP 2.0 是新增加的.在之前的版本中,这两个对象是由数组表示的,而相关的方法是分散在RequestHandlerComponent,Router,Dis ...
- CakePHP之控制器
控制器 控制器是MVC中的“C”. 如果你的网站使用Cake框架制作,一般根据url地址和通过路由,就会找到正确的控制器,然后控制器的动作就会被调用. 一个控制器需要解释请求数据.确保使用正确的模型. ...
- CakePHP之Model
模型 模型在应用程序中是作为业务层而存在的(怎么感觉是数据层......).这就意味着,模型应当负责管理几乎所有涉及数据的事情,其合法性,以及你的业务领域中数据在工作流程中的演化和互动 . 通常模型类 ...
随机推荐
- [STL]双层级配置器
考虑到过多“小型区块”可能造成的内存碎片问题,SGI设计了双层级配置器: 第一级配置器直接调用malloc()和free(): 第二级配置器分两种情况:当配置区块大于128字节时,调用第一级配置器:当 ...
- 关于playmaker play animation出现警告 The AnimationClip 'xxx' used by the Animati ...
转载自网络: 出现这个提示: The AnimationClip 'xxx' used by the Animation component 'xxx' must be marked as Legac ...
- 解决IIS应用程序池DefaultAppPool关闭超时错误
错误系统日志: 为应用程序池“DefaultAppPool”提供服务的进程关闭时间超过了限制.进程 ID 是“3060”. 有关更多信息,请参阅在http://go.microsoft.com/fwl ...
- list、set、map的特点
java 集合(list.set.map)的特点 集合相关的类有一大堆,一般也只用到常用的方法增删改查,而且它它们的方法名也基本一样,所以一直都不知道什么时候用什么集合, 今天趁有空特意从网上整理资料 ...
- CentOS如何开启ssh远程连接
假设VPS采用centos,再假设用较新版本6.5. VPS上可能没有安装桌面,但一般来说都会安装ssh,并且防火墙默认开放22端口. 那就从ssh开始. # 安装ssh,默认已安装好 # yum i ...
- linux 命令案例学习——文件搜索
两个搜索文件的工具 locate ——仅仅通过文件名查找文件 find ——依据文件的各种属性在既定目录(包括子目录)里查找 一个通常与文件搜索命令一起使用.处理搜索结果文件列表的命令 xa ...
- 第一个Struts2程序
Struts2.3.16, Tomcat6.0.37,Java8 /web.xml <?xml version="1.0" encoding="UTF-8" ...
- GLSL基础
GLSL基础 OpenGL Shading Language GLSL作为一种着色语言是纯粹的和GPU打交道的计算机语言.因为GPU是多线程并行处理器,所以GLSL直接面向SIMD模型的多线程计算.G ...
- Android与OpenCV——重新下载安装和OpenCV匹配的Android开发环境
Android与OpenCV——重新下载安装和OpenCV匹配的Android开发环境 !!OpenCV4Android开发之旅(一)----OpenCV2.4简介及 app通过Java接口调用Ope ...
- HDU 4648 Magic Pen 6 思路
官方题解: 题意转化一下就是: 给出一列数a[1]...a[n],求长度最长的一段连续的数,使得这些数的和能被M整除. 分析: 设这列数前i项和为s[i], 则一段连续的数的和 a[i]+a[i+1] ...