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
模型 模型在应用程序中是作为业务层而存在的(怎么感觉是数据层......).这就意味着,模型应当负责管理几乎所有涉及数据的事情,其合法性,以及你的业务领域中数据在工作流程中的演化和互动 . 通常模型类 ...
随机推荐
- HDU4916 Count on the path(树dp??)
这道题的题意其实有点略晦涩,定义f(a,b)为 minimum of vertices not on the path between vertices a and b. 其实它加一个minimum ...
- UVA 562 Dividing coins (01背包)
题意:给你n个硬币,和n个硬币的面值.要求尽可能地平均分配成A,B两份,使得A,B之间的差最小,输出其绝对值.思路:将n个硬币的总价值累加得到sum, A,B其中必有一人获得的钱小于等于sum/2 ...
- POJ 1325
#include<iostream> #include<stdio.h> #define MAXN 105 using namespace std; int _m[MAXN][ ...
- SQL技术内幕-12 SQL优化方法论前言
我推荐的一种使用自顶向下的优化论.这种方法,首先分析实例级的等待时间,在通过一系列步骤将其不断细化,知道找出系统中导致大量等待的进程/组件.一旦找出这些令人讨厌的进程,就可以集中优化他们了,一下是这种 ...
- asp.net网站中添加百度地图功能
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- Lucene基于IKAnalyzer配置的词典扩充
在web项目的src目录下创建IKAnalyzer.cfg.xml文件,内容如下 <?xml version="1.0" encoding="UTF-8" ...
- Java IO(二)
字节流 字符流: FileReader FileWriter BufferedReader BufferedWriter 字节流: FileInputStream FileOutputStream B ...
- MySql经典语句
1.三个函数: LENGTH SUBSTR LOCATE )) order by WebSiteShopUrl desc 2.序号 两种方法 第一种方法: ) ) as it 第二种方法: ; ...
- 阿里云centos6搭建vpn
下载脚本 wget http://latrell.me/wp-content/uploads/vpn_centos6.sh 运行脚本 chmod a+x vpn_centos6.sh ./vpn_ce ...
- CodeForces485A——Factory(抽屉原理)
Factory One industrial factory is reforming working plan. The director suggested to set a mythical d ...