【问题标题】:laravel link does work but button does notlaravel 链接确实有效,但按钮无效
【发布时间】:2016-02-03 00:46:16
【问题描述】:

在 laravel 中,我有一个名为 ZOEKEN 的链接,它转到“zoekenindex”。有效

  <li> {{HTML::link('zoekenindex','ZOEKEN')}}</li>

但我想要一个按钮而不是链接:

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

此输出:“无法为命名路由“zoekenindex”生成 URL,因为此类路由不存在。”

我不明白为什么,因为当我使用链接代码时该路线有效。

有人知道为什么会这样吗?

【问题讨论】:

    标签: twitter-bootstrap laravel


    【解决方案1】:

    Laravel 在您的路由文件中没有找到任何名为 zoekenindex 的名称路由。

    创建名称路由:

    Route::get('zoekenindex', array('as' => 'zoekenindex', 'uses' => 'yourController@index'))
    

    您的按钮:默认情况下,引导程序将创建按钮。不用担心链接。

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

    Laravel 助手:

    {{ link_to_route('zoekenindex', 'Left', null, array('class' => 'btn btn-default')) }}
    

    ,如果您不喜欢创建名称路由,请使用以下内容:

    <a href="{{ URL::to('zoekenindex') }}" class="btn btn-default">Left</a>
    

    Laravel 助手:

    {{ link_to('zoekenindex', 'Left', array('class' => 'btn btn-default')) }}
    

    【讨论】:

    • 不错。我不知道 bootstrap 会通过将 btn 类添加到锚标记来创建按钮。切换实际上解决了我在单击按钮启动下载后没有“弹出备份”的小问题。
    【解决方案2】:
    <button href="{{ url('zoekenindeze') }}" type="button" class="btn btn-default">Left</button>
    

    它将指向 zoekenindeze 路线

    【讨论】:

      【解决方案3】:

      Laravel 5

      {!! HTML::linkRoute('admin.users.edit', $user->display_name, array($user->id), ['class' => 'btn btn-default']) !!}
      

      【讨论】:

        猜你喜欢
        • 2021-02-18
        • 2010-10-22
        • 2021-06-30
        • 2010-09-30
        • 1970-01-01
        • 1970-01-01
        • 2017-01-30
        • 1970-01-01
        相关资源
        最近更新 更多