本文整理汇总了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);
}
}