繁体   English   中英

如何解决未定义的索引错误?

[英]How can I solve the undefined index error?

我正在使用Laravel 5.6,但遇到了问题。 我有以下代码:

<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell <taylor@laravel.com>
 */

$uri = urldecode(
    parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);

// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
    return false;
}

require_once __DIR__.'/public/index.php';

并得到这个错误:

PHP注意:未定义的索引:REQUEST_URI。

即使当我使用以下command:php -S localhost:8000通过终端运行服务器时command:php -S localhost:8000

出现以下消息:

未找到
在此服务器上找不到请求的资源。

我不知道为什么会这样。 路由“ /”在我的web.php中定义

<?php

    /*
    |--------------------------------------------------------------------------
    | Web Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register web routes for your application. These
    | routes are loaded by the RouteServiceProvider within a group which
    | contains the "web" middleware group. Now create something great!
    |
    */
    //Contiene todas las rutas que vamos a trabajar
    Route::get('/', function () {
        return view('welcome');
    });

您的代码期望具有该索引,但是您正在CLI模式下运行PHP。 $ _SERVER superglobal的REQUEST_URI变量仅在您通过浏览器访问脚本时可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM