dongshi4773
2017-03-10 13:17
浏览 22
已采纳

Laravel 4将刀片输入传递给控制器

I have a project in laravel 4.

In my blade file i have:

<div class="col-sm-12">
            <a href="{{ action('HomeController@getMore') }}" data-limit="12" data-gap="12">Show more </a>
</div>

I want to pass my limit and gap to the controller. In the controller i use Input::get('limit'); but i get back a null. Even Input::all() returns null.

Any tips?

Thank you!

图片转代码服务由CSDN问答提供 功能建议

我在laravel 4中有一个项目。

在我的刀片文件中 有:

 &lt; div class =“col-sm-12”&gt; 
&lt; a href =“{{action('HomeController @ getMore')}}  “data-limit =”12“data-gap =”12“&gt;显示更多&lt; / a&gt; 
&lt; / div&gt; 
   
 
 

我想要 将我的限制和差距传递给控制器​​。 在控制器中我使用Input :: get('limit'); 但我得到了一个null。 Even Input :: all()返回null。

任何提示?

谢谢!

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doujing6436 2017-03-10 13:21
    已采纳

    Try this:

    <div class="col-sm-12">
            <a href="{{ action('HomeController@getMore', ['dataLimit'=>12, 'dataGap'=>12]) }}" data-limit="12" data-gap="12">Show more </a>
    

    And ensure that your route and controller passed params. Route must be configured with dataLimit and dataGap params, and controller method must accept it.

    打赏 评论
  • douhao9203 2017-03-10 13:21

    Input is for forms. If you want to use anchors, you will have to pass parameters to url like this

    <a href="/url?limit=12&gap=12" >Show more </a>
    

    This makes them optional to your controller. You just need to get them with request().

    $limit = request('limit');
    $gap = request('gap');
    
    打赏 评论
  • douzen1880 2017-03-10 13:45

    HTML(VIEW) CODE

    1. Code for a tag <a href="url('submit/Parameters...')">click ok </a>

    2. Form code <form method="POST" action="{{url('submit/Parameters..')}}" method="post"> {{ csrf_field() }} ... </form>

    ROUTE CODE

    1. route code with action Route::get('user/{id}', function ($id) { echo "id is : ".$id ; });

    2. route code for controller
      Route::get('user/{id}', 'UserController@show');

      CONTROLLERS CODE
      <?php

    namespace App\Http\Controllers;
    use App\User;
    use App\Http\Controllers\Controller;

    class ShowProfile extends Controller { public function index($id) { echo $id; } }

    for more information you see following like https://laravel.com/docs/5.4/controllers and https://laravel.com/docs/5.4/routing

    打赏 评论

相关推荐 更多相似问题