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


PHP BaseElementModel::getUrlFormat方法代码示例

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


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

示例1: prepareAncestorsForElement

 /**
  * @param BaseElementModel $element
  * @param $data
  *
  * @return null|CategoryModel
  */
 private function prepareAncestorsForElement(BaseElementModel $element, $data)
 {
     $parentCategory = null;
     $data = $this->freshenString($data);
     // Don't connect empty fields
     if (!empty($data)) {
         // This we append before the slugified path
         $categoryUrl = str_replace('{slug}', '', $element->getUrlFormat());
         // Find matching element by URI (dirty, not all categories have URI's)
         $criteria = craft()->elements->getCriteria(ElementType::Category);
         $criteria->groupId = $element->groupId;
         $criteria->uri = $categoryUrl . craft()->import->slugify($data);
         $criteria->limit = 1;
         $parentCategory = $criteria->first();
     }
     return $parentCategory;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:23,代码来源:Import_CategoryService.php

示例2: setUniqueUri

 /**
  * Sets the URI on an element using a given URL format, tweaking its slug if necessary to ensure it's unique.
  *
  * @param BaseElementModel $element
  *
  * @throws Exception
  */
 public static function setUniqueUri(BaseElementModel $element)
 {
     $urlFormat = $element->getUrlFormat();
     // No URL format, no URI.
     if (!$urlFormat) {
         $element->uri = null;
         return;
     }
     // No slug, or a URL format with no {slug}, just parse the URL format and get on with our lives
     if (!$element->slug || !static::doesUrlFormatHaveSlugTag($urlFormat)) {
         $element->uri = craft()->templates->renderObjectTemplate($urlFormat, $element);
         return;
     }
     $uniqueUriConditions = array('and', 'locale = :locale', 'uri = :uri');
     $uniqueUriParams = array(':locale' => $element->locale);
     if ($element->id) {
         $uniqueUriConditions[] = 'elementId != :elementId';
         $uniqueUriParams[':elementId'] = $element->id;
     }
     $slugWordSeparator = craft()->config->get('slugWordSeparator');
     $maxSlugIncrement = craft()->config->get('maxSlugIncrement');
     for ($i = 0; $i < $maxSlugIncrement; $i++) {
         $testSlug = $element->slug;
         if ($i > 0) {
             $testSlug .= $slugWordSeparator . $i;
         }
         $originalSlug = $element->slug;
         $element->slug = $testSlug;
         $testUri = craft()->templates->renderObjectTemplate($urlFormat, $element);
         // Make sure we're not over our max length.
         if (strlen($testUri) > 255) {
             // See how much over we are.
             $overage = strlen($testUri) - 255;
             // Do we have anything left to chop off?
             if (strlen($overage) > strlen($element->slug) - strlen($slugWordSeparator . $i)) {
                 // Chop off the overage amount from the slug
                 $testSlug = $element->slug;
                 $testSlug = substr($testSlug, 0, strlen($testSlug) - $overage);
                 // Update the slug
                 $element->slug = $testSlug;
                 // Let's try this again.
                 $i -= 1;
                 continue;
             } else {
                 // We're screwed, blow things up.
                 throw new Exception(Craft::t('The maximum length of a URI is 255 characters.'));
             }
         }
         $uniqueUriParams[':uri'] = $testUri;
         $totalElements = craft()->db->createCommand()->select('count(id)')->from('elements_i18n')->where($uniqueUriConditions, $uniqueUriParams)->queryScalar();
         if ($totalElements == 0) {
             // OMG!
             $element->slug = $testSlug;
             $element->uri = $testUri;
             return;
         } else {
             $element->slug = $originalSlug;
         }
     }
     throw new Exception(Craft::t('Could not find a unique URI for this element.'));
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:68,代码来源:ElementHelper.php


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