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