您不能使用HTML
类以这种方式生成链接,并且已将其 ( HTML
)L4
作为最佳实践删除,如果您HTML
为此使用原始标记会更容易,尽管还有其他方法,例如 ( bootstrapper,我没有尝试过),L3
但在(IMO)中它是压倒性的。检查这个论坛链接。
或者,您可以使用自定义宏,只需在 中创建一个新文件(myMacros.php)app\libraries
,它应该是 asapp\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>');