引导按钮中的 Laravel 路由

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20728674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:41:54  来源:igfitidea点击:

Laravel route in bootstrap button

twitter-bootstraplaravel

提问by JeffreyR

I want to make a button that links to route: normindex

我想制作一个链接到路由的按钮:normindex

This blow does not seem to work.

这一击似乎不起作用。

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

This below does work but generates a link, not a button.

下面这个确实有效,但会生成一个链接,而不是一个按钮。

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

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

Does anyone have any idea?

有谁有想法吗?

回答by Anam

Try the following:

请尝试以下操作:

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

or

或者

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

回答by Manuel Pedrera

Well, they don't work because HTML::link()will output a full HTML link, while your second attempt just uses plain text in the hrefattribute, so there is no way for Laravel to know that it needs to include something in there.

好吧,它们不起作用,因为HTML::link()将输出完整的 HTML 链接,而您的第二次尝试只是在href属性中使用纯文本,因此 Laravel 无法知道它需要在其中包含某些内容。



You can try this:

你可以试试这个:

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

The route()helper will print the URL of the route that you pass to it. This will need a named route in your routes.phpfile, such as:

route()助手将打印您传递给它的路线的URL。这将需要您的routes.php文件中的命名路由,例如:

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

回答by blahblahber

Shanaka's solution worked, but the single quote defining the class is in the wrong place and it's missing a close parenthesis.

Shanaka 的解决方案有效,但定义类的单引号位置错误,并且缺少右括号。

Correction:

更正:

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

回答by Shanaka WickramaArachchi

Add a button classfrom bootstrap to your route

将引导程序中的按钮类添加到您的路线

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

回答by Fabian Farinas

Use an <a>tag with bootstrap btn class:

使用<a>带有 bootstrap btn 类的标签:

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

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