您不能使用HTML 类以这种方式生成链接,作为最佳做法,它已从L4 中删除(HTML),如果您使用原始HTML 标记会更容易这个,虽然在L3中有其他方法,比如(bootstrapper,我没有尝试过),但在(IMO)中它是压倒性的。
检查这个forum link。
您也可以使用自定义宏,只需在app\libraries 中创建一个新文件(myMacros.php),它应该为app\libraries\myMacros.php 并将以下代码放入此文件中
HTML::macro('link_nested', function($route, $title = null, $attributes = array(), $secure = null, $nested = null, $params = array())
{
$url = URL::to_route($route, $params, $secure);
$title = $title ?: $url;
if (empty($attributes)) {
$attributes = null;
}
return '<a href="'.$url.'"'.HTML::attributes($attributes).'>'.$nested.''.HTML::entities($title).'</a>';
});
然后,将其包含在您的start.php 中
require path('app').'/libraries/myMacros.php';
最后,在你的模板中使用它
HTML::link_nested('user.accountview', 'Delete', array('class'=>'btn'), '', '<i class="icon-trash"></i>', array($project->id));
对于submit 按钮,请将其添加到您的myMacros.php
HTML::macro('submit_nested', function($title = null, $attributes = array(), $nested = null)
{
$title = $title ?: 'Submit';
if (empty($attributes)) {
$attributes = null;
}
return '<button type="submit" ' . HTML::attributes($attributes).'>' . $nested .' '. HTML::entities($title).'</button>';
});
最后,像这样使用它
HTML::submit_nested('Search', array('class'=>'someClass', 'name' => 'submit'), '<i class="icon-trash"></i>');