【问题标题】:Can't retrieve get variables in Laravel无法在 Laravel 中检索获取变量
【发布时间】:2015-11-02 14:22:56
【问题描述】:

我的 routes.php 中有以下内容:

Route::controller('hello', 'HelloController');

我的 HelloController.php 中有以下内容:

use Input;
use Illuminate\Http\Request;

public function getIndex(Request $request) 
{
    echo "hi";
    $param = $request->input('param');
    echo $param;
}

当我转到我的 URL /hello?param=testparam 时,不会为 $param 值输出任何内容。有什么想法吗?

更新 当我在我的 URL 中输入这个:index.php/hello?param=testparam。它工作正常。这让我相信它与漂亮的 URL 有关。

【问题讨论】:

  • 你有什么错误吗?你试过 $param = $request->param;
  • @zlen 我正在调用 lluminate\Http\Request 并且仍然为空。
  • @KhanShahrukh 没有错误,我也试过了。
  • 好的,如我所见,您没有调用该函数。这样做:Route::controller('hello', 'HelloController@getIndex');
  • 你使用的是什么版本的 Laravel?

标签: php http laravel-5


【解决方案1】:

遇到了类似的问题。我这样做了:

url('/hello/?param=testparam')

在为我工作之间添加一个斜线。

【讨论】:

    【解决方案2】:

    正如我在上面的评论中所说,经过测试,您错过了包括对函数 getIndex 的调用。

    你必须这样做:

    Route::controller('hello', 'HelloController@getIndex');
    

    【讨论】:

    猜你喜欢
    • 2019-01-28
    • 1970-01-01
    • 2023-03-30
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    • 2023-03-06
    相关资源
    最近更新 更多