Php Laravel图像提交按钮
我想知道是否有一种方法可以自定义中提交按钮的外观(改为图像) 目前,我的提交按钮代码如下所示:Php Laravel图像提交按钮,php,twitter-bootstrap,laravel,laravel-3,Php,Twitter Bootstrap,Laravel,Laravel 3,我想知道是否有一种方法可以自定义中提交按钮的外观(改为图像) 目前,我的提交按钮代码如下所示: {{ Form::open('project/delete', 'DELETE') }} {{ Form::hidden('id', $project->id) }} {{ Form::submit('Delete project', array('class'=>'btn')); }} {{ Form::close() }} 它正确地完成了他的工作。但我不知道如何定制submit按钮并
{{ Form::open('project/delete', 'DELETE') }}
{{ Form::hidden('id', $project->id) }}
{{ Form::submit('Delete project', array('class'=>'btn')); }}
{{ Form::close() }}
它正确地完成了他的工作。但我不知道如何定制submit按钮并将其作为引导图标,例如使用<代码>
我尝试使用:
{{ HTML::decode(HTML::link_to_route('project_delete', '<i class="icon-trash"></i>', array($project->id))); }}
{{HTML::decode(HTML::link_to_route('project_delete','',数组($project->id));}
但是我的路由/函数调用有问题 不能使用HTML作为
输入的值。如果您尝试
,您会发现它不起作用。此外,使用第二种方法这样的链接是不可行的,因为它实际上并没有提交表单
你最好的办法是用按钮
<button type="submit"><i class="icon-trash"></i></button>
您不能使用HTML
类以这种方式生成链接,它(HTML
)已从L4
中删除,作为最佳实践,如果您使用原始HTML
标记来实现这一点会更容易,尽管在L3
中有类似(,我没有尝试过)的替代方法,但在(IMO)中它是压倒性的。
看看这个
或者,您可以使用自定义宏,只需在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>';
});
最后,在模板中使用它,如
HTML::link_nested('user.accountview', 'Delete', array('class'=>'btn'), '', '<i class="icon-trash"></i>', array($project->id));
最后,像这样使用它
HTML::submit_nested('Search', array('class'=>'someClass', 'name' => 'submit'), '<i class="icon-trash"></i>');
HTML::submit_嵌套('Search',array('class'=>'someClass','name'=>'submit'),'');
您不接受答案,有什么原因吗?
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>');