本文整理汇总了PHP中HtmlHelper::link方法的典型用法代码示例。如果您正苦于以下问题:PHP HtmlHelper::link方法的具体用法?PHP HtmlHelper::link怎么用?PHP HtmlHelper::link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlHelper
的用法示例。
在下文中一共展示了HtmlHelper::link方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: autoLinkText
public static function autoLinkText($text, $options = array())
{
static $Html;
if (!$Html) {
if (!class_exists('HtmlHelper', false)) {
\App::import('Helper', 'Html');
}
$Html = new \HtmlHelper();
$Html->tags = $Html->loadConfig();
}
// Email
$atom = '[a-z0-9!#$%&\'*+\\/=?^_`{|}~-]';
$text = preg_replace_callback('/(' . $atom . '+(?:\\.' . $atom . '+)*@[a-z0-9-]+(?:\\.[a-z0-9-]+)*)/i', function ($matches) use($Html, $options) {
return $Html->link($matches[0], "mailto:" . $matches[0], $options);
}, $text);
// http / web
$text = preg_replace_callback('#(?<!href="|">)((?:https?|ftp|nntp)://[^\\s<>()]+)#i', function ($matches) use($Html, $options) {
return $Html->link($matches[0], $matches[0], $options);
}, $text);
// http / web - part 2
$text = preg_replace_callback('#(?<!href="|">)(?<!http://|https://|ftp://|nntp://)(www\\.[^\\n\\%\\ <]+[^<\\n\\%\\,\\.\\ <])(?<!\\))#i', function ($matches) use($Html, $options) {
return $Html->link($matches[0], "http://" . $matches[0], $options);
}, $text);
return $text;
}
示例2: link
/**
* Returns link to remote action
*
* Returns a link to a remote action defined by <i>options[url]</i>
* (using the url() format) that's called in the background using
* XMLHttpRequest. The result of that request can then be inserted into a
* DOM object whose id can be specified with <i>options[update]</i>.
*
* Examples:
* <code>
* link("Delete this post",
* array("update" => "posts", "url" => "delete/{$postid->id}"));
* link(imageTag("refresh"),
* array("update" => "emails", "url" => "list_emails" ));
* </code>
*
* By default, these remote requests are processed asynchronous during
* which various callbacks can be triggered (for progress indicators and
* the likes).
*
* Example:
* <code>
* link (word,
* array("url" => "undo", "n" => word_counter),
* array("complete" => "undoRequestCompleted(request)"));
* </code>
*
* The callbacks that may be specified are:
*
* - <i>loading</i>:: Called when the remote document is being
* loaded with data by the browser.
* - <i>loaded</i>:: Called when the browser has finished loading
* the remote document.
* - <i>interactive</i>:: Called when the user can interact with the
* remote document, even though it has not
* finished loading.
* - <i>complete</i>:: Called when the XMLHttpRequest is complete.
*
* If you for some reason or another need synchronous processing (that'll
* block the browser while the request is happening), you can specify
* <i>options[type] = synchronous</i>.
*
* You can customize further browser side call logic by passing
* in Javascript code snippets via some optional parameters. In
* their order of use these are:
*
* - <i>confirm</i>:: Adds confirmation dialog.
* -<i>condition</i>:: Perform remote request conditionally
* by this expression. Use this to
* describe browser-side conditions when
* request should not be initiated.
* - <i>before</i>:: Called before request is initiated.
* - <i>after</i>:: Called immediately after request was
* initiated and before <i>loading</i>.
*
* @param string $title Title of link
* @param mixed $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
* @param array $options Options for JavaScript function
* @param string $confirm Confirmation message. Calls up a JavaScript confirm() message.
*
* @return string HTML code for link to remote action
* @link http://book.cakephp.org/1.3/en/The-Manual/Core-Helpers/AJAX.html#link
*/
function link($title, $url = null, $options = array(), $confirm = null)
{
if (!isset($url)) {
$url = $title;
}
if (!isset($options['url'])) {
$options['url'] = $url;
}
if (!empty($confirm)) {
$options['confirm'] = $confirm;
unset($confirm);
}
$htmlOptions = $this->__getHtmlOptions($options, array('url'));
$options += array('safe' => true);
unset($options['escape']);
if (empty($options['fallback']) || !isset($options['fallback'])) {
$options['fallback'] = $url;
}
$htmlDefaults = array('id' => 'link' . intval(mt_rand()), 'onclick' => '');
$htmlOptions = array_merge($htmlDefaults, $htmlOptions);
$htmlOptions['onclick'] .= ' event.returnValue = false; return false;';
$return = $this->Html->link($title, $url, $htmlOptions);
$callback = $this->remoteFunction($options);
$script = $this->Javascript->event("'{$htmlOptions['id']}'", "click", $callback);
if (is_string($script)) {
$return .= $script;
}
return $return;
}
示例3: evaluate
function evaluate($affiliate, $params, $team, $strict, $text_reason, $complete, $absolute_url)
{
$matches = Set::extract("/Upload[type_id={$this->config[0]}]", $params['Upload']);
$unapproved = Set::extract('/Upload[approved=0]', $matches);
if (empty($unapproved)) {
if ($text_reason) {
$this->reason = sprintf(__('have uploaded the %s', true), $this->document);
} else {
App::import('Helper', 'Html');
$html = new HtmlHelper();
$url = array('controller' => 'people', 'action' => 'document_upload', 'type' => $this->config[0]);
if ($absolute_url) {
$url = $html->url($url, true);
} else {
$url['return'] = true;
}
$this->reason = $html->link(sprintf(__('have uploaded the %s', true), $this->document), $url);
}
} else {
$this->reason = sprintf(__('wait until your %s is approved', true), $this->document);
}
if (!$strict) {
return true;
}
if (is_array($params) && array_key_exists('Upload', $params)) {
$date = date('Y-m-d', strtotime($this->config[1]));
$matches = Set::extract("/Upload[type_id={$this->config[0]}][valid_from<={$date}][valid_until>={$date}]", $params['Upload']);
if (!empty($matches)) {
return true;
}
}
return false;
}
示例4: link
public function link($title, $url = null, $options = array(), $confirmMessage = false)
{
if ($this->isAllowed($url)) {
return parent::link($title, $url, $options, $confirmMessage);
}
return '';
}
示例5: evaluate
function evaluate($affiliate, $params, $team, $strict, $text_reason, $complete, $absolute_url)
{
$events = array();
if ($text_reason) {
foreach ($this->events as $event) {
$events[] = $event['Event']['name'];
}
} else {
App::import('Helper', 'Html');
$html = new HtmlHelper();
foreach ($this->events as $event) {
$url = array('controller' => 'events', 'action' => 'view', 'event' => $event['Event']['id']);
if ($absolute_url) {
$url = $html->url($url, true);
} else {
$url['return'] = true;
}
$events[] = $html->link($event['Event']['name'], $url);
}
}
$this->reason = __('have previously registered for the', true) . ' ' . implode(' ' . __('or', true) . ' ', $events);
if (is_array($params) && array_key_exists('Registration', $params)) {
$registered = Set::extract('/Registration/Event/id', $params);
$prereqs = array_intersect($registered, $this->config);
if (!empty($prereqs)) {
return true;
}
}
return false;
}
示例6: abm
function abm($id, $controller, $enclosed = null)
{
/* Load HTML helper */
App::import('Helper', 'Html');
$html = new HtmlHelper();
$abm = ' ';
if ($enclosed) {
$abm .= "<{$enclosed}>";
}
$abm .= $html->link(__('[Edit]', true), array('controller' => $controller, 'action' => 'edit', $id)) . ' ';
$abm .= $html->link(__('[×]', true), array('controller' => $controller, 'action' => 'delete', $id), null, sprintf(__('Are you sure you want to delete # %s?', true), $id));
if ($enclosed) {
$abm .= "</{$enclosed}>";
}
return $abm;
}
示例7: link
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true)
{
$linkUrl = parent::url($url);
$currentUrl = $this->here;
// Remove paging from currentUrl
// @TODO if another named param goes after paging it do it's thing
$pieces = explode('/', $currentUrl);
$paging = end($pieces);
if (strpos($paging, 'page:') === 0) {
array_pop($pieces);
$currentUrl = join('/', $pieces);
}
if (isset($htmlAttributes['strict']) and $htmlAttributes['strict']) {
$htmlAttributes['currentOn'] = $url;
}
$currentOverride = false;
if (isset($htmlAttributes['currentOn']) && !is_null($htmlAttributes['currentOn'])) {
if ($currentUrl === parent::url($htmlAttributes['currentOn'])) {
$currentOverride = true;
}
}
if (strpos($currentUrl, $linkUrl) === 0 && (!isset($htmlAttributes['currentOn']) || is_null($htmlAttributes['currentOn'])) || $currentOverride === true) {
if (!isset($htmlAttributes['class'])) {
$htmlAttributes['class'] = '';
}
$classes = explode(' ', $htmlAttributes['class']);
if (!isset($classes['current'])) {
$classes[] = 'current';
}
$htmlAttributes['class'] = join(' ', $classes);
}
unset($htmlAttributes['currentOn']);
return parent::link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle);
}
示例8: evaluate
function evaluate($affiliate, $params, $team, $strict, $text_reason, $complete, $absolute_url)
{
if ($text_reason) {
$this->reason = sprintf(__('have signed the %s waiver', true), $this->waiver);
} else {
App::import('Helper', 'Html');
$html = new HtmlHelper();
$url = array('controller' => 'waivers', 'action' => 'sign', 'waiver' => $this->config[0], 'date' => $this->date);
if ($absolute_url) {
$url = $html->url($url, true);
} else {
$url['return'] = true;
}
$this->reason = $html->link(sprintf(__('have signed the %s waiver', true), $this->waiver), $url);
}
$this->redirect = array('controller' => 'waivers', 'action' => 'sign', 'waiver' => $this->config[0], 'date' => $this->date);
if (!$strict) {
$this->invariant = true;
return true;
}
if (is_array($params) && array_key_exists('Waiver', $params)) {
$matches = array_intersect($this->config, Set::extract("/Waiver/WaiversPerson[valid_from<={$this->date}][valid_until>={$this->date}]/waiver_id", $params));
if (!empty($matches)) {
$this->invariant = true;
return true;
}
}
return false;
}
示例9: link
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true)
{
// $parsedUrl = rtrim(parent::url($url), '/');
// $parsedUrl = rtrim($parsedUrl, '/index');
// $currentUrl = rtrim($this->here, '/');
// $currentUrl = rtrim($currentUrl, '/index');
// $linksToCurrentPage = (bool)($parsedUrl === $currentUrl);
//
// $containsCurrentPage = (bool)(strpos($currentUrl, $parsedUrl) === 0);
//
// if ($linksToCurrentPage or (!isset($htmlAttributes['strict']) and $containsCurrentPage)) {
// if (isset($htmlAttributes['class'])) {
// $htmlAttributes['class'] = $htmlAttributes['class'] + ' current';
// } else {
// $htmlAttributes['class'] = 'current';
// }
// }
//
// unset($htmlAttributes['strict']);
$parsedUrl = rtrim(parent::url($url), '/');
$parsedUrl = rtrim($parsedUrl, '/index');
$currentUrl = rtrim($this->here, '/');
$currentUrl = rtrim($currentUrl, '/index');
$linksToCurrentPage = (bool) ($parsedUrl === $currentUrl);
$isPartOfUrl = (bool) (strpos($currentUrl, $parsedUrl) === 0);
if ($linksToCurrentPage or !isset($htmlAttributes['strict']) and $isPartOfUrl) {
if (isset($htmlAttributes['class'])) {
$htmlAttributes['class'] += ' current';
} else {
$htmlAttributes['class'] = 'current';
}
}
return parent::link($title, $url, $htmlAttributes, $confirmMessage, $escapeTitle);
}
示例10: link
/**
* Returns link to remote action
*
* Returns a link to a remote action defined by <i>options[url]</i>
* (using the url() format) that's called in the background using
* XMLHttpRequest. The result of that request can then be inserted into a
* DOM object whose id can be specified with <i>options[update]</i>.
*
* Examples:
* <code>
* link("Delete this post",
* array("update" => "posts", "url" => "delete/{$postid->id}"));
* link(imageTag("refresh"),
* array("update" => "emails", "url" => "list_emails" ));
* </code>
*
* By default, these remote requests are processed asynchronous during
* which various callbacks can be triggered (for progress indicators and
* the likes).
*
* Example:
* <code>
* link (word,
* array("url" => "undo", "n" => word_counter),
* array("complete" => "undoRequestCompleted(request)"));
* </code>
*
* The callbacks that may be specified are:
*
* - <i>loading</i>:: Called when the remote document is being
* loaded with data by the browser.
* - <i>loaded</i>:: Called when the browser has finished loading
* the remote document.
* - <i>interactive</i>:: Called when the user can interact with the
* remote document, even though it has not
* finished loading.
* - <i>complete</i>:: Called when the XMLHttpRequest is complete.
*
* If you for some reason or another need synchronous processing (that'll
* block the browser while the request is happening), you can specify
* <i>options[type] = synchronous</i>.
*
* You can customize further browser side call logic by passing
* in Javascript code snippets via some optional parameters. In
* their order of use these are:
*
* - <i>confirm</i>:: Adds confirmation dialog.
* -<i>condition</i>:: Perform remote request conditionally
* by this expression. Use this to
* describe browser-side conditions when
* request should not be initiated.
* - <i>before</i>:: Called before request is initiated.
* - <i>after</i>:: Called immediately after request was
* initiated and before <i>loading</i>.
*
* @param string $title Title of link
* @param string $href Href string "/products/view/12"
* @param array $options Options for JavaScript function
* @param string $confirm Confirmation message. Calls up a JavaScript confirm() message.
* @param boolean $escapeTitle Escaping the title string to HTML entities
*
* @return string HTML code for link to remote action
*/
function link($title, $href = null, $options = array(), $confirm = null, $escapeTitle = true) {
if (!isset($href)) {
$href = $title;
}
if (!isset($options['url'])) {
$options['url'] = $href;
}
if (isset($confirm)) {
$options['confirm'] = $confirm;
unset($confirm);
}
$htmlOptions = $this->__getHtmlOptions($options, array('url'));
$htmlDefaults = array('id' => 'link' . intval(mt_rand()), 'onclick' => '');
$htmlOptions = array_merge($htmlDefaults, $htmlOptions);
$htmlOptions['onclick'] .= ' return false;';
$return = $this->Html->link($title, $href, $htmlOptions, null, $escapeTitle);
$callback = $this->remoteFunction($options);
$script = $this->Javascript->event("'#{$htmlOptions['id']}'", "click", $callback);
if (is_string($script)) {
$return .= $script;
}
return $return;
}
示例11: tweetButton
/**
* create tweet button
*
* @see http://dev.twitter.com/pages/tweet_button
* @param string $label
* @param array $options
* @param boolean $dataAttribute
* @param boolean $scriptInline
* @return string
*/
public function tweetButton($label = null, $options = array(), $dataAttribute = false, $scriptInline = false)
{
$attributes = array();
$defaults = array('class' => 'twitter-share-button', 'url' => '', 'via' => '', 'text' => '', 'related' => '', 'count' => 'horizontal', 'lang' => 'en', 'counturl' => '');
if (empty($label)) {
$label = 'Tweet';
}
$options = am($defaults, $options);
$attributes['class'] = $options['class'];
unset($options['class']);
$options['count'] = strtolower($options['count']);
if (!in_array($options['count'], array('none', 'horizontal', 'vertical'))) {
$options['count'] = 'none';
}
$options = Set::filter($options);
if ($dataAttribute) {
foreach ($options as $key => $val) {
$attributes['data-' . $key] = $val;
}
$options = array();
}
$out = $this->Html->link($label, 'http://twitter.com/share' . Router::queryString($options), $attributes);
$out .= $this->Html->script('http://platform.twitter.com/widgets.js', array('inline' => $scriptInline));
return $this->output($out);
}
示例12: link
public function link($title, $url = null, $options = array(), $confirmMessage = false)
{
if (!is_array($url)) {
$tmp = Router::parse($url);
} else {
$tmp = $url;
}
if (!isset($this->request->params['action'])) {
$this->request->params['action'] = 'index';
}
if (!isset($tmp['action'])) {
$tmp['action'] = 'index';
}
if ($tmp['controller'] == $this->request->params['controller']) {
if (!isset($options) || !is_array($options)) {
$options = array();
}
if (!isset($options['class'])) {
$options['class'] = 'current-controller';
} else {
$options['class'] .= ' current-controller';
}
if ($tmp['action'] == $this->request->params['action'] || $this->request->params['controller'] == 'Pages' && $this->request->params['action'] == 'display' && $this->request->params['pass'][0] == $tmp['action']) {
$options['class'] .= ' current-page';
if (isset($tmp[0]) && isset($this->request->params['pass']) && isset($this->request->params['pass'][0]) && $tmp[0] == $this->request->params['pass'][0]) {
$options['class'] .= ' current-item';
}
}
}
return parent::link($title, $url, $options, $confirmMessage);
}
示例13: link
function link($title, $url = null, $options = array(), $confirmMessage = false)
{
if (!isset($url['language']) && isset($this->params['language'])) {
$url['language'] = $this->params['language'];
}
return parent::link($title, $url, $options, $confirmMessage);
}
示例14: link
/**
* Генерация ссылки с проверкой доступа по ролевой модели
* @param string $title
* @param null $url
* @param array $options
* @param bool $confirmMessage
* @return null|string
*/
function link($title, $url = null, $options = array(), $confirmMessage = false)
{
if ($this->_aclCheck($url)) {
return parent::link($title, $url, $options, $confirmMessage);
} else {
return null;
}
}
示例15: link
function link($title, $url = NULL, $options = array(), $confirmMessage = false)
{
if (!is_array($url)) {
return parent::link($title, $url . $this->getLinkTitle($title), $options, $confirmMessage);
} else {
return parent::link($title, $url, $options, $confirmMessage);
}
}