本文整理匯總了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);
}
}
示例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;
}
示例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);
}
}