【问题标题】:Learning Laravel学习 Laravel
【发布时间】:2015-10-26 20:25:14
【问题描述】:

我是 Laravel 的新手(我正在使用最新版本),并且在我的“routes.php”文件中有以下内容:

 Route::get('/books', function(){
        return 'Books Index';
    });

 Rout::get('/books/{genre}', function($genre){
         return "Books in the {$genre} category";
    });

如果我在浏览器中输入这些::

http://localhost/laravel/public/books             // first address
http://localhost/laravel/public/books/movies     // second address

为了测试这两个地址,我得到一个错误页面,上面说出了点问题。如果我评论第二条路线并尝试第一个地址,那么它可以工作。即使我评论第一条路线,第二个地址也永远不会起作用。因此,只要两条路由都存在,这些地址都不起作用。

我做错了什么?

谢谢。

【问题讨论】:

  • 您在第二条路线上缺少右括号和括号,这只是一个错字吗?
  • @user3158900 这是一个错字,否则 IDE 将不允许我运行代码。不过,感谢您指出这一点。

标签: php laravel


【解决方案1】:

在您的第二条路线上,您缺少一个 e(Rout != 路线)。如果出现这样的语法错误,您的路由文件将无法正确执行。

我本来只想添加评论,但我的声誉还不够好。

【讨论】:

    【解决方案2】:

    作为参考,将来,您的 laravel 项目应该将这样的错误写入某处的日志文件。这应该在文件 app/start/global.php 中的块中定义,如下所示:

    /*
    |--------------------------------------------------------------------------
    | Application Error Logger
    |--------------------------------------------------------------------------
    |
    | Here we will configure the error logger setup for the application which
    | is built on top of the wonderful Monolog library. By default we will
    | build a basic log file setup which creates a single file for logs.
    |
    */
    
    Log::useFiles('/var/log/laravel/laravel.log');
    

    当您在项目中遇到问题时,跟踪此日志文件可以让您有所了解。

    【讨论】:

    • 我认为最好使用相对路径:Log::useFiles(storage_path().'/logs/laravel.log');
    【解决方案3】:

    你不需要在路线的开头有斜线,只使用:

    Route::get('books', function(){ ...
    

    http://laravel.com/docs/5.1/routing#basic-routing

    【讨论】:

      【解决方案4】:

      你需要改变“Rout” -> “Route”

      Route::get('/books/{genre}', function($genre){
           return "Books in the {$genre} category";
      });
      

      【讨论】:

        【解决方案5】:

        如果你有语法错误,请在 app/config/app.php 文件中的调试模式。 Laravel 提供了格式良好的错误消息,否则默认会显示“出错了”

        遵循语法

        旧代码

        'debug' => false
        

        新代码

        'debug' => true
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-06-09
          • 1970-01-01
          • 1970-01-01
          • 2015-05-01
          • 2013-03-24
          • 2020-10-22
          相关资源
          最近更新 更多