2013-12-22 21 views
4

我想做一个链接到路由按钮:normindexLaravel路径在自举按钮

这种打击似乎并不奏效。

<button href={{ HTML::link('normindex')}} type="button" class="btn btn-default">Left</button> 
<button href="normindex" type="button" class="btn btn-default">Left</button> 

这下面的工作,但生成一个链接,而不是一个按钮。

{{ HTML::link('normindex','Left')}}

没有人有任何想法?

回答

3

嗯,他们不工作,因为HTML::link()将输出一个完整的HTML链接,而你的第二次尝试只是在href属性中使用纯文本,所以没有办法让Laravel知道它需要包含的东西在那里。


你可以试试这个:

<button href="{{ route('normindex') }}" type="button" class="btn btn-default">Left</button> 

route()助手将打印您传递给它的路线的URL。这将需要一个名为路线在routes.php文件,如:

Route::get('your-path', array('as' => 'normindex', function() 
{ 
    // do stuff 
})); 
+0

你的路径可以这是Normcontroller @ index。暂停我正在使用的完整路由是:Route :: get('normindex','Normcontroller @ index'); – user2322791

+0

'your-path'应该是您在浏览器中用来访问该路线的值。在我的示例中:'http:// example.com/your-path' –

8

尝试以下操作:

<a href="{{ URL::route('normindex') }}" class="btn btn-default"> Norm Index </a> 

link_to_route('normindex', 'Norm Index', null, array('class' => 'btn btn-default')); 
+0

“无法为指定路由生成URL”normindex“,因为此路由不存在。” 奇怪的是它确实存在: Route :: get('normindex','Normcontroller @ index'); – user2322791

+0

这应该是Route :: get('normindex',数组('as'=>'normindex','uses'=>'Normcontroller @ index')); – Anam

0

从引导添加按钮类到您的路线

{!! Html::linkRoute('posts.show','cancel',array($post->id),array('class=>'btn btn-danger btn-block')!!}