博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cakephp之查询
阅读量:4657 次
发布时间:2019-06-09

本文共 2348 字,大约阅读时间需要 7 分钟。

 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); }

转载于:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/5505994.html

你可能感兴趣的文章
我的Python分析成长之路8
查看>>
泛型在三层中的应用
查看>>
SharePoint2010 -- 管理配置文件同步
查看>>
.Net MVC3中取得当前区域的名字(Area name)
查看>>
获得屏幕像素以及像素密度
查看>>
int与string转换
查看>>
adb命令 判断锁屏
查看>>
推荐一个MacOS苹果电脑系统解压缩软件
查看>>
1035等差数列末项计算
查看>>
CDMA鉴权
查看>>
ASP.NET MVC Identity 兩個多個連接字符串問題解決一例
查看>>
过滤器与拦截器区别
查看>>
第二阶段站立会议7
查看>>
JAVA多线程
查看>>
delphi 更改DBGrid 颜色技巧
查看>>
POJ 2031 Building a Space Station
查看>>
任意阶幻方(魔方矩阵)C语言实现
查看>>
织梦教程
查看>>
杭电多校 Harvest of Apples 莫队
查看>>
C/C++心得-结构体
查看>>