【问题标题】:Laravel 4.2 Cannot access Query ParametersLaravel 4.2 无法访问查询参数
【发布时间】:2015-01-16 17:02:35
【问题描述】:

我正在使用 laravel 4.2nginx,通过简单的 Get 路由,我无法使用 'Input::get('id') 访问查询参数' 。如果我尝试 Request::fullUrl(),即使我提供了,我也看不到任何查询参数。

我的路线是:

Route::get('user' , 'UserController@show');

在我刚刚使用的控制器中,

Input::get('name');

并访问如下路线:

localhost/user?name=foo

Nginx 配置是:

server {
        listen 80;
       root /home/ubuntu/project/public;
       index index.html index.php;
       server_name  localhost;



       # set expiration of assets to MAX for caching
        location ~* \.(html|ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;
        }

       location / {
                # First attempt to server request as file, then
                # as directory, then fall back to displaying a 404
        try_files $uri $uri/ /index.php;
       }

       location /doc/ {
                alias /usr/share/doc/;
                autoindex on;
                allow 127.0.0.1;
                allow ::1;
                deny all;
       }
       error_page 404 /404.html;

       location ~ \.php$ {
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_param QUERY_STRING $query_string;
                fastcgi_read_timeout 36000;
                include fastcgi_params;
       }

       location /server-status {
              stub_status on;
              access_log off;
              allow all;
       }

}

【问题讨论】:

    标签: php laravel nginx get


    【解决方案1】:

    在你的 nginx 站点配置中,你应该像这样添加$query_string

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    

    【讨论】:

    • 我这样的菜鸟错误。谢谢杰罗德夫。干杯!
    • 别担心,几个月前我犯了同样的错误。这就是为什么我记得这个错误。 ;)
    • 如果它解决了你的问题,你为什么不把它标记为答案@Farhan Salam
    猜你喜欢
    • 2015-07-28
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    • 2015-01-12
    • 2019-02-17
    • 1970-01-01
    • 2021-01-16
    • 1970-01-01
    相关资源
    最近更新 更多