7.4.1.7 link
このセクションには保留されている変更があります. More information about translations
link(string $title, mixed $url = null, array $htmlAttributes = array(), string $confirmMessage = false, boolean $escapeTitle = true)
General purpose method for creating HTML links. Use $htmlAttributes to specify attributes for the element.
<?php echo $html->link('Enter', '/pages/home', array('class'=>'button','target'=>'_blank')); ?>
<?php echo $html->link('Enter', '/pages/home', array('class'=>'button','target'=>'_blank')); ?>
Will output:
<a href="/ja/pages/home" class="button" target="_blank">Enter</a>
Specify $confirmMessage to display a javascript confirm() dialog.
<?php echo $html->link(
'Delete',
array('controller'=>'recipes', 'action'=>'delete', 6),
array(),
"Are you sure you wish to delete this recipe?"
);?>
<?php echo $html->link('Delete',array('controller'=>'recipes', 'action'=>'delete', 6),array(),"Are you sure you wish to delete this recipe?");?>
Will output:
<a href="/ja/recipes/delete/6" onclick="return confirm('Are you sure you wish to delete this recipe?');">Delete</a>
Query strings can also be created with link().
<?php echo $html->link('View image', array(
'controller' => 'images',
'action' => 'view',
1,
'?' => array( 'height' => 400, 'width' => 500))
);
<?php echo $html->link('View image', array('controller' => 'images','action' => 'view',1,'?' => array( 'height' => 400, 'width' => 500)));
Will output:
<a href="/ja/images/view/1?height=400&width=500">View image</a>
HTML special characters in $title will be converted to HTML entities. To disable this conversion, set the escape option to false in the $htmlAttributes, or set $escapeTitle to false.
<?php
echo $html->link(
$html->image("recipes/6.jpg", array("alt" => "Brownies")),
"recipes/view/6",
array('escape'=>false)
);
echo $html->link(
$html->image("recipes/6.jpg", array("alt" => "Brownies")),
"recipes/view/6",
null, null, false
);
?>
<?phpecho $html->link($html->image("recipes/6.jpg", array("alt" => "Brownies")),"recipes/view/6",array('escape'=>false));echo $html->link($html->image("recipes/6.jpg", array("alt" => "Brownies")),"recipes/view/6",null, null, false);?>
Both will output:
<a href="/ja/recipes/view/6">
<img src="/img/recipes/6.jpg" alt="Brownies" />
</a>
Also check HtmlHelper::url method for more examples of different types of urls.


























