當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityManager::createNativeQuery方法代碼示例

本文整理匯總了PHP中Kdyby\Doctrine\EntityManager::createNativeQuery方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManager::createNativeQuery方法的具體用法?PHP EntityManager::createNativeQuery怎麽用?PHP EntityManager::createNativeQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::createNativeQuery方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: searchByTag

 /**
  * Method used for search functionality
  *
  * @param int $tagID
  * @return array
  */
 public function searchByTag($tagID)
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addEntityResult(Page::class, 'p');
     $rsm->addFieldResult('p', 'id', 'id');
     $rsm->addFieldResult('p', 'title', 'title');
     $rsm->addFieldResult('p', 'intro', 'intro');
     $rsm->addFieldResult('p', 'intro_html', 'introHtml');
     //$rsm->addFieldResult('p', 'text', 'text');
     $rsm->addMetaResult('p', 'author', 'author');
     $rsm->addMetaResult('p', 'url', 'url');
     $rsm->addFieldResult('p', 'created_at', 'createdAt');
     $rsm->addFieldResult('p', 'is_draft', 'isDraft');
     $rsm->addFieldResult('p', 'published_at', 'publishedAt');
     $rsm->addFieldResult('p', 'allowed_comments', 'allowedComments');
     $rsm->addScalarResult('commentsCount', 'commentsCount', 'integer');
     $rsm->addIndexByColumn('p', 'id');
     $rsm->addJoinedEntityResult(Locale::class, 'l', 'p', 'locale');
     $rsm->addFieldResult('l', 'locale_id', 'id');
     $rsm->addFieldResult('l', 'locale_name', 'name');
     $rsm->addFieldResult('l', 'locale_code', 'code');
     $rsm->addFieldResult('l', 'locale_lang', 'lang');
     $rsm->addFieldResult('l', 'locale_default', 'default');
     $nativeQuery = $this->em->createNativeQuery('SELECT p.id, p.title, p.intro, p.intro_html, p.author, p.url,
                 p.created_at, p.is_draft, p.published_at,
                 p.allowed_comments, COUNT(c.page) AS commentsCount,
                 l.id AS locale_id, l.name AS locale_name, l.code AS locale_code,
                 l.lang AS locale_lang, l.default AS locale_default
          FROM (
             SELECT pts.page_id, pts.tag_id
             FROM page_tag pts
             WHERE pts.tag_id = :id
             GROUP BY pts.page_id
          ) AS pt
          JOIN page p ON (p.id = pt.page_id AND p.is_draft = 0 AND p.published_at <= NOW())
          JOIN locale l ON (l.id = p.locale)
          LEFT JOIN comment c ON (c.page = pt.page_id)
          GROUP BY pt.page_id', $rsm)->setParameter('id', $tagID);
     $pages = $nativeQuery->getResult();
     $this->em->createQuery('SELECT PARTIAL page.{id}, tags FROM ' . Page::class . ' page
          LEFT JOIN page.tags tags INDEX BY tags.id
          WHERE page.id IN (:ids)')->setParameter('ids', array_keys($pages))->execute();
     return $pages;
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:50,代碼來源:PageFacade.php

示例2: findRolesThatAreNotParents

 /**
  * @return Role[]
  */
 public function findRolesThatAreNotParents()
 {
     $rsm = new ResultSetMappingBuilder($this->em);
     $rsm->addEntityResult(Role::class, 'r');
     $rsm->addFieldResult('r', 'id', 'id');
     $rsm->addFieldResult('r', 'name', 'name');
     $rsm->addJoinedEntityResult(Role::class, 'p', 'r', 'parent');
     $rsm->addFieldResult('p', 'parent_id', 'id');
     $rsm->addFieldResult('p', 'parent_name', 'name');
     $nativeQuery = $this->em->createNativeQuery('
         SELECT r.id, r.name, p.id AS parent_id, p.name AS parent_name
         FROM role r
         LEFT JOIN role p ON (p.id = r.parent_id)
         WHERE r.id NOT IN(
             SELECT r2.parent_id FROM role r2 WHERE r2.parent_id IS NOT NULL
         )
     ', $rsm);
     return $nativeQuery->getResult();
 }
開發者ID:blitzik,項目名稱:CMS,代碼行數:22,代碼來源:UserFacade.php


注:本文中的Kdyby\Doctrine\EntityManager::createNativeQuery方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。