If $url starts with "http://" this is treated as an external link. Else,
it is treated as a path to controller/action and parsed with the
UrlHelper::build() method.
If the $url is empty, $title is used instead.
### Options
- escape Set to false to disable escaping of title and attributes.
- escapeTitle Set to false to disable escaping of title. Takes precedence
over value of escape)
- confirm JavaScript confirmation message.
public link ( string $title, string | array | null $url = null, array $options = [] ) : string | ||
$title | string | The content to be wrapped by `` tags. |
$url | string | array | null | Cake-relative URL or array of URL parameters, or external URL (starts with http://) |
$options | array | Array of options and HTML attributes. |
리턴 | string | An `` element. |
/** * Generate a link if the target url is authorized for the logged in user * * @param string $title link's title. * @param string|array|null $url url that the user is making request. * @param array $options Array with option data. * @return string */ public function link($title, $url = null, array $options = []) { if ($this->isAuthorized($url)) { $linkOptions = $options; unset($linkOptions['before'], $linkOptions['after']); return Hash::get($options, 'before') . parent::link($title, $url, $linkOptions) . Hash::get($options, 'after'); } return false; }
/** * Keep query string params for pagination/filter for this link, * e.g. after edit action. * * ### Options * * - `escape` Set to false to disable escaping of title and attributes. * - `escapeTitle` Set to false to disable escaping of title. Takes precedence * over value of `escape`) * - `confirm` JavaScript confirmation message. * * @param string $title The content to be wrapped by <a> tags. * @param string|array|null $url URL or array of URL parameters, or * external URL (starts with http://) * @param array $options Array of options and HTML attributes. * @return string An `<a />` element. * @return string Link */ public function completeLink($title, $url = null, array $options = []) { if (is_array($url)) { // Add query strings if (!isset($url['?'])) { $url['?'] = []; } $url['?'] += $this->request->query; } return parent::link($title, $url, $options); }
/** * {@inheritdoc} */ public function link($title, $url = null, array $options = array()) { $url = Router::url($url, ['full' => true]); if ('html' == $this->getType()) { return parent::link($title, $url, $this->_mergeAttributes($options, $this->config('attributes.link'))); } if (empty($url)) { return $title; } $options += ['templates' => []]; $options['templates'] += ['link' => ':title: :url']; return Text::insert($options['templates']['link'], compact('title', 'url')); }
/** * Create an html link. * * @param string $title * @param null $url * @param array $options * @return string */ public function link($title, $url = null, array $options = []) { $options = $this->addClass($options, $this->_class(__FUNCTION__)); $options = Hash::merge(['escapeTitle' => false, 'clear' => false, 'label' => $title], $options); $isClear = $options['clear']; unset($options['clear']); // Set title in html tag. if ($options['escapeTitle'] === false && !empty($title) && !$isClear) { $title = $this->tag('span', $title, ['class' => $this->_class(__FUNCTION__) . '-title']); } $options = $this->_getBtnClass($options); $options = $this->_getToolTipAttr($options); list($options, $iconOptions) = $this->_createIconAttr($options); if (isset($iconOptions['createIcon'])) { unset($iconOptions['createIcon']); $title = $this->icon($options['icon'], $iconOptions) . PHP_EOL . $title; unset($options['icon']); } if (isset($options['iconInline'])) { unset($options['iconInline']); } unset($options['label']); return parent::link($title, $url, $options); }
/** * Create an html link. * * @param string $title * @param null $url * @param array $options * @return string */ public function link($title, $url = null, array $options = []) { $options = $this->addClass($options, $this->getClass(__FUNCTION__)); $options = Hash::merge(['escapeTitle' => false, 'title' => false, 'isClear' => false], $options); $isClear = $options['isClear']; unset($options['isClear']); if ($options['title'] == false) { unset($options['title']); } // Set buttons if (!empty($options['button'])) { $button = [$this->_btnPrefix]; if ($options['button'] !== true) { foreach ((array) $options['button'] as $btn) { if ($btn !== true) { $button[] = $this->_btnPrefix . '-' . $btn; } } } unset($options['button']); $options = $this->addClass($options, implode(' ', $button)); } // Set title in html tag if ($options['escapeTitle'] == false && !empty($title) && !$isClear) { $title = $this->tag('span', $title, ['class' => $this->getClass(__FUNCTION__) . '-title']); } // Set link icon if (isset($options['icon'])) { $_iconOptions = []; if (isset($options['iconClass'])) { $_iconOptions = $this->addClass($_iconOptions, $options['iconClass']); unset($options['iconClass']); } if (isset($options['iconInline'])) { $iconClass = $this->getClass('icon') . ' ' . $this->_iconPrefix . $options['icon']; $options = $this->addClass($options, $iconClass); unset($options['iconInline']); } else { $options['escape'] = false; $title = $this->icon($options['icon'], $_iconOptions) . PHP_EOL . $title; } unset($options['icon']); } // Set uikit tooltip if (isset($options['tooltip'])) { $_toolTipPos = 'top'; if (is_string($options['tooltip']) && !isset($options['title'])) { $options['title'] = $options['tooltip']; } if (isset($options['tooltipPosition'])) { $_toolTipPos = $options['tooltipPosition']; unset($options['tooltipPosition']); } $toolTipOptions = ['data-uk-tooltip' => "pos:'{$_toolTipPos}'", 'title' => !isset($options['title']) ? (string) $options['tooltip'] : $options['title']]; unset($options['tooltip']); $options = Hash::merge($toolTipOptions, $options); } return parent::link($title, $url, $options); }
/** * Creates an HTML link * @param string $title The content to be wrapped by <a> tags * @param string|array|null $url Cake-relative URL or array of URL * parameters or external URL * @param array $options Array of options and HTML attributes * @return string */ public function link($title, $url = null, array $options = []) { $options = $this->optionsDefaults(['escape' => false, 'title' => $title], $options); $options['title'] = trim(h(strip_tags($options['title']))); list($title, $options) = $this->addIconToText($title, $options); $options = $this->addTooltip($options); return parent::link($title, $url, $options); }