zoukankan      html  css  js  c++  java
  • 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);
    }
  • 相关阅读:
    C#泛型
    QT QML Keys 处理注意事项
    Ubuntu 16.04 安装 QT Create 5.3.1
    在VMWare中安装了Ubuntu16.04,想要 Win10 中通过 SecureCRT 来操作
    Ubuntu16在VMWare中使用共享文件夹
    QT QLineEdit 获取焦点/获取焦点后全选字符
    QT Layout 布局的重要性
    QT ToolBar 工具栏浮动状态
    QT 格式化字符串功能
    QT 窗体之间(MainWindow 和 Dialog)数据传递
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/5505994.html
Copyright © 2011-2022 走看看