当前位置: 首页>>代码示例>>PHP>>正文


PHP ORM::count方法代码示例

本文整理汇总了PHP中ORM::count方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::count方法的具体用法?PHP ORM::count怎么用?PHP ORM::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ORM的用法示例。


在下文中一共展示了ORM::count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: render_iterator

function render_iterator($class, $page_limit, $template)
{
    list($params, $limit, $page) = build_iterator_where($page_limit);
    $item_count = ORM::count($class, $params);
    $pager_calculator = new PagerCalculator($item_count, $limit);
    $page = $pager_calculator->calculate($page);
    $offset = $pager_calculator->get_offset();
    $limit = $pager_calculator->get_limit();
    $maxpage = $pager_calculator->get_maxpage();
    $items = ORM::all($class, $params, array('ctime', 'desc'), array($offset, $limit));
    $urlparams = array('page' => $page, 'nick' => isset($params['nick']) && $params['nick'] !== null ? rawurlencode($params['nick']) : null, 'day' => isset($params['ctime']) && isset($_GET['day']) ? $_GET['day'] : null, 'week' => isset($params['ctime']) && isset($_GET['week']) ? $_GET['week'] : null, 'url' => isset($params['original_url']) && isset($_GET['url']) ? $_GET['url'] : null, 'limit' => $limit != $page_limit && isset($_GET['limit']) ? $limit : null);
    extract($GLOBALS);
    // since this is an ajax query with only the data included, we can set expires header safely when not on the last page
    if (is_xhr_request() && $page !== $maxpage) {
        header('Expires: ' . date('r', strtotime('+1 week', $_SERVER['REQUEST_TIME'])));
    }
    include APPROOT . '/' . $template;
}
开发者ID:sztanpet,项目名称:aoiboard,代码行数:18,代码来源:functions.php

示例2: define

<?php

define('APPROOT', dirname(__FILE__)) . '/';
include_once APPROOT . '/lib/constants.php';
include_once APPROOT . '/model/pic.class.php';
include_once APPROOT . '/lib/functions.php';
$dbcnx = new PDO(DB_DSN, DB_USER, DB_PW, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
ORM::set_dbcnx($dbcnx);
$limit = PAGE_LIMIT_PIC;
list($params, $limit, $page) = build_iterator_where(PAGE_LIMIT_PIC);
$item_count = ORM::count('Pic', $params);
$maxpage = max(ceil($item_count / $limit) - 1, 0);
$item_count_on_last_page = $item_count - floor($item_count / $limit) * $limit;
if ($item_count_on_last_page == 0) {
    $maxpage -= 1;
}
$urlparams = $_GET;
$visited_pages = cookie_list('visited_pages');
include APPROOT . '/html/component/pager.html.php';
开发者ID:sztanpet,项目名称:aoiboard,代码行数:19,代码来源:pager.php

示例3: validate

 function validate()
 {
     $this->invalidFields = array();
     $this->errors = array();
     $uniques = array();
     foreach ($this->schema as $field) {
         // Simple required field validation
         $numeric_fields = array('int', 'tinyint', 'bigint', 'float', 'double', 'decimal');
         $field_is_numeric = array_search($field->type, $numeric_fields) !== false;
         if ((!$field_is_numeric && $this->_data[$field->name] === NULL || $field_is_numeric && !is_numeric($this->_data[$field->name])) && $field->required && !$field->primaryKey) {
             $this->invalidFields[$field->name][] = i18n::get('This field is required');
             if (!in_array(self::ERR_REQUIRED, $this->errors)) {
                 $this->errors[] = self::ERR_REQUIRED;
             }
         }
         // Gather unique fields
         if ($field->unique && !$field->primaryKey) {
             $uniques[] = $field->name;
         }
     }
     // Unique field validation only for new model instances
     if (!$this->getPrimaryKey()) {
         // Loop through each unique field and retrieve instances;
         // Could be refactored to reduce the number of queries made
         foreach ($uniques as $field_name) {
             $c = new Criteria($this->model_name);
             $c->add($field_name, $this->_data[$field_name]);
             if (ORM::count($c) > 0) {
                 $this->invalidFields[$field_name][] = i18n::get('Already registered');
                 if (!in_array(self::ERR_UNIQUE, $this->errors)) {
                     $this->errors[] = self::ERR_UNIQUE;
                 }
             }
         }
     }
     if (count($this->invalidFields) > 0) {
         return false;
     } else {
         return true;
     }
 }
开发者ID:rev087,项目名称:kennel,代码行数:41,代码来源:Model.php


注:本文中的ORM::count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。