【问题标题】:Laravel3 how to send variable into controller from viewLaravel3如何从视图将变量发送到控制器
【发布时间】:2013-09-04 21:53:52
【问题描述】:

我现在正在学习 laravel 3,我有一个技术问题。我有一个作者列表,我正在尝试创建一些链接来设置过滤器以对这些作者进行排序。

我尝试将默认参数设置为按名称排序,它可以工作,但我无法通过任何其他过滤器。

这是我的路线:

Route::get('authors', array('as'=>'authors', 'uses'=>'authors@index'));

这是我的控制器功能:

public function get_index($filter="name"){
    return View::make('authors.index')
        ->with('title', 'Authors list')
        ->with('authors', Author::order_by($filter)->get());
}

这是我认为试图发送我想要的过滤器的链接

{{ HTML::link_to_route('authors', 'Id', array('id')) }}
{{ HTML::link_to_route('authors', 'Name', array('name')) }}

我尝试从视图发送的参数(id 和名称)永远不会到达控制器,因此它始终使用默认参数。

谢谢!

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    您没有设置任何路由参数,您必须执行以下操作:

    Route::get('authors/(:any?)', array('as'=>'authors', 'uses'=>'authors@index'));
    

    查看文档:http://three.laravel.com/docs/routing#wildcards

    【讨论】:

      猜你喜欢
      • 2016-12-02
      • 1970-01-01
      • 2012-07-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多