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


PHP QueryBuilder::getSQL方法代码示例

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


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

示例1: getSqlCriteria

 /**
  * @param Query|QueryBuilder $criteria
  *
  * @return string (sql)
  */
 protected function getSqlCriteria($criteria)
 {
     if ($criteria instanceof QueryBuilder) {
         return $criteria->getQuery()->getSQL();
     } elseif ($criteria instanceof Query) {
         return $criteria->getSQL();
     } else {
         throw new \Exception(sprintf('Criteria must be instance of Query or QueryBuilder, instance of %s given', get_class($criteria)));
     }
 }
开发者ID:Codenetz,项目名称:AclBundle,代码行数:15,代码来源:AclFilter.php

示例2: getPaginator

 /**
  * Get Paginator
  * 
  * @param integer $limit ( limit per page )
  * @param array $options
  * @return \Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination
  */
 protected function getPaginator($limit = 30, $options = array())
 {
     $page = $this->get('request')->query->get('page', 1);
     $cnt = 0;
     if ($this->get('request')->query->has('page')) {
         $page = $this->get('request')->query->get('page');
         $this->get('session')->set('_pager_' . $this->get('request')->get('_route'), $page);
     } elseif ($this->get('session')->has('_pager_' . $this->get('request')->get('_route'))) {
         $page = $this->get('session')->get('_pager_' . $this->get('request')->get('_route'));
     }
     if (isset($options['total_item_count']) and (int) $options['total_item_count']) {
         $cnt = $options['total_item_count'];
     }
     $this->paginator = $this->get('knp_paginator');
     if (is_array($this->query) or $this->query instanceof QueryBuilder) {
         $pagination = $this->paginator->paginate($this->query, $page, $limit, $options);
     } elseif ($this->query instanceof NativeQuery) {
         $rsm = new ResultSetMapping();
         $rsm->addScalarResult('cnt', 'cnt');
         $q = strstr($this->query->getSQL(), " FROM ");
         $q = "SELECT COUNT(*) cnt " . $q;
         $cntQuery = $this->em->createNativeQuery($q, $rsm)->setParameters($this->query->getParameters());
         try {
             $cnt = $cntQuery->getSingleScalarResult();
         } catch (\Doctrine\Orm\NoResultException $e) {
             $cnt = 0;
         }
         $sql = $this->query->getSQL();
         $pagination = $this->paginator->paginate(array());
         $sort_name = $pagination->getPaginatorOption('sortFieldParameterName');
         $sort_direction_name = $pagination->getPaginatorOption('sortDirectionParameterName');
         if ($this->get('request')->query->has($sort_name) and $this->get('request')->query->has($sort_direction_name)) {
             $sql .= ' ORDER BY ' . $this->get('request')->query->get($sort_name) . ' ' . $this->get('request')->query->get($sort_direction_name);
         } elseif (isset($options['default_sort']) and $options['default_sort']) {
             $sql .= ' ORDER BY ';
             foreach ($options['default_sort'] as $field => $type) {
                 $sql .= $field . ' ' . $type . ',';
             }
             $sql = trim($sql, ',');
         }
         if (!isset($options['not_use_limit_offset'])) {
             $offset = $limit * ($page - 1);
             $this->query->setSQL($sql . ' LIMIT ' . $limit . ' OFFSET ' . $offset);
         }
         $pagination->setCurrentPageNumber($page);
         $pagination->setItemNumberPerPage($limit);
         $pagination->setTotalItemCount($cnt);
         $pagination->setItems($this->query->getResult());
     }
     $pagination->setTemplate($this->container->getParameter('zk2_admin_panel.pagination_template'));
     $pagination->setSortableTemplate($this->container->getParameter('zk2_admin_panel.sortable_template'));
     return compact('pagination');
 }
开发者ID:zk2,项目名称:admin-panel-bundle,代码行数:60,代码来源:AdminPanelController.php


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