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
模型 模型在应用程序中是作为业务层而存在的(怎么感觉是数据层......).这就意味着,模型应当负责管理几乎所有涉及数据的事情,其合法性,以及你的业务领域中数据在工作流程中的演化和互动 . 通常模型类 ...
随机推荐
- 【三】php之梗
1.php没有顶级作用域,所以你没办法在函数内部使用变量(参数传递除外,而且常量是可以的哟),所以你的变量即使是static的也不能在函数外声明函数里用.除非借助global关键字修饰变量才可以.但是 ...
- adb或appium下多设备中指定设备的启动
一.先用adb devices列出所有设备序列号 List of devices attached012BDC7N78954789 device132AEC8N57897458 device 二.进入 ...
- zoj 2358,poj 1775 Sum of Factorials(数学题)
题目poj 题目zoj //我感觉是题目表述不确切,比如他没规定xi能不能重复,比如都用1,那么除了0,都是YES了 //算了,这种题目,百度来的过程,多看看记住就好 //题目意思:判断一个非负整数n ...
- EditText 属性
android:layout_gravity="center_vertical" 设置控件显示的位置:默认top,这里居中显示,还有bottom android:hint=&quo ...
- ExtJs之Panel基本布局
<!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...
- C++ std命名空间
1.命名空间是一种特殊的作用域,它包含了处于该作用域中所有标示符.命名空间使用namespace 来声明,并使用{}来界定命名空间的作用域,例如: namespace func{ int val=0; ...
- NOIP模拟赛 by hzwer
2015年10月04日NOIP模拟赛 by hzwer (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...
- PushBackInputStream与PushBackInputStreamReader的用法
举个例子:获取XX内容 PushBackInputStream pb=new PushBackInputStream(in,4);//4制定缓冲区大小 byte[] buf=new byte[4]; ...
- RabbitMQ安装与搭建
1.下载Erlang,最新版本是erl8.1 ,地址:http://erlang.org/download/otp_win64_19.1.exe 网上很多资料说安装后要配置环境变量,不过我安装最新的版 ...
- Sails 自定义 model 方法
Sails 自定义 model 方法 在 Sails 中 model 提供了一些原生的静态方法,如 .create(), .update(), .destroy(), .find(), 等. 在实际业 ...