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


PHP BaseElementModel::getUrl方法代碼示例

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


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

示例1: getTableAttributeHtml

 /**
  * @inheritDoc IElementType::getTableAttributeHtml()
  *
  * @param BaseElementModel $element
  * @param string           $attribute
  *
  * @return mixed|string
  */
 public function getTableAttributeHtml(BaseElementModel $element, $attribute)
 {
     switch ($attribute) {
         case 'link':
             $url = $element->getUrl();
             if ($url) {
                 return '<a href="' . $url . '" target="_blank" data-icon="world" title="' . Craft::t('Visit webpage') . '"></a>';
             } else {
                 return '';
             }
         case 'uri':
             $url = $element->getUrl();
             if ($url) {
                 $value = $element->uri;
                 if ($value == '__home__') {
                     $value = '<span data-icon="home" title="' . Craft::t('Homepage') . '"></span>';
                 } else {
                     // Add some <wbr> tags in there so it doesn't all have to be on one line
                     $find = array('/');
                     $replace = array('/<wbr>');
                     $wordSeparator = craft()->config->get('slugWordSeparator');
                     if ($wordSeparator) {
                         $find[] = $wordSeparator;
                         $replace[] = $wordSeparator . '<wbr>';
                     }
                     $value = str_replace($find, $replace, $value);
                 }
                 return '<a href="' . $url . '" target="_blank" class="go" title="' . Craft::t('Visit webpage') . '"><span dir="ltr">' . $value . '</span></a>';
             } else {
                 return '';
             }
         default:
             // Is this a custom field?
             if (preg_match('/^field:(\\d+)$/', $attribute, $matches)) {
                 $fieldId = $matches[1];
                 $field = craft()->fields->getFieldById($fieldId);
                 if ($field) {
                     $fieldType = $field->getFieldType();
                     if ($fieldType && $fieldType instanceof IPreviewableFieldType) {
                         // Was this field value eager-loaded?
                         if ($fieldType instanceof IEagerLoadingFieldType && $element->hasEagerLoadedElements($field->handle)) {
                             $value = $element->getEagerLoadedElements($field->handle);
                         } else {
                             $value = $element->getFieldValue($field->handle);
                         }
                         $fieldType->setElement($element);
                         return $fieldType->getTableAttributeHtml($value);
                     }
                 }
                 return '';
             }
             $value = $element->{$attribute};
             if ($value instanceof DateTime) {
                 return '<span title="' . $value->localeDate() . ' ' . $value->localeTime() . '">' . $value->uiTimestamp() . '</span>';
             }
             return HtmlHelper::encode($value);
     }
 }
開發者ID:codeforamerica,項目名稱:oakland-beta,代碼行數:66,代碼來源:BaseElementType.php

示例2: getElementUrlForLocale

 /**
  * Gets a element URL for the specified locale.
  *
  * @param Element            $element
  * @param string|LocaleModel $locale
  *
  * @return string
  */
 public function getElementUrlForLocale(BaseElementModel $element, $locale)
 {
     $this->validateLocale($locale);
     $oldLocale = $element->locale;
     $oldUri = $element->uri;
     $element->locale = $locale;
     $element->uri = craft()->elements->getElementUriForLocale($element->id, $locale);
     $url = $element->getUrl();
     $element->locale = $oldLocale;
     $element->uri = $oldUri;
     return $url;
 }
開發者ID:amite,項目名稱:arc-va,代碼行數:20,代碼來源:SitemapService.php

示例3: getTableAttributeHtml

 /**
  * @inheritDoc IElementType::getTableAttributeHtml()
  *
  * @param BaseElementModel $element
  * @param string           $attribute
  *
  * @return mixed|string
  */
 public function getTableAttributeHtml(BaseElementModel $element, $attribute)
 {
     switch ($attribute) {
         case 'uri':
             $url = $element->getUrl();
             if ($url) {
                 $value = $element->uri;
                 if ($value == '__home__') {
                     $value = '<span data-icon="home" title="' . Craft::t('Homepage') . '"></span>';
                 } else {
                     // Add some <wbr> tags in there so it doesn't all have to be on one line
                     $find = array('/');
                     $replace = array('/<wbr>');
                     $wordSeparator = craft()->config->get('slugWordSeparator');
                     if ($wordSeparator) {
                         $find[] = $wordSeparator;
                         $replace[] = $wordSeparator . '<wbr>';
                     }
                     $value = str_replace($find, $replace, $value);
                 }
                 return '<a href="' . $url . '" target="_blank" class="go"><span dir="ltr">' . $value . '</span></a>';
             } else {
                 return '';
             }
         default:
             $value = $element->{$attribute};
             if ($value instanceof DateTime) {
                 return '<span title="' . $value->localeDate() . ' ' . $value->localeTime() . '">' . $value->uiTimestamp() . '</span>';
             }
             return HtmlHelper::encode($value);
     }
 }
開發者ID:scisahaha,項目名稱:generator-craft,代碼行數:40,代碼來源:BaseElementType.php


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