【问题标题】:"Whoops, looks like something went wrong." Laravel 4.1“哎呀,看起来像出事了。”拉拉维尔 4.1
【发布时间】:2014-07-13 23:58:14
【问题描述】:

好的,所以我刚刚开始检查 Laravel 4.1,我遇到了一个问题,我不明白为什么?问题是我在屏幕上收到这条消息“哎呀,好像出了点问题。”但我真的什么都没做。我创建了一个视图、一个控制器并添加了一个路由,这就是这些文件中的内容

查看

<h1>Author's home page</h1>

控制器

class AuthorsController extends BaseController {

    public $restful = true;
    public function getIndex () {
        return View::make('authors.index'); //authors.index because it's in the authors folder within the views folder
    }
}

路线

Route::get('authors', 'AuthorsController@getIndex'); 

所以逻辑表明,当我转到作者 URL 时,它应该在 AurhorsController 页面中加载 getIndex 函数并显示位于视图 > authors 中的 index.blade.php 文件。

如果是这样,那么我不知道为什么这不起作用!任何帮助,将不胜感激。提前致谢。

编辑 1

这是实际错误

throw new NotFoundHttpException();

编辑 2

【问题讨论】:

  • "Whoops, looks like something went wrong." 是显示在所有错误页面上的通用文本。您能否粘贴实际的错误消息(查找异常)?
  • @MarttiLaine 我关闭了调试,哎呀这是错误... throw new NotFoundHttpException();

标签: php laravel laravel-4 url-routing


【解决方案1】:

看起来 Laravel 试图访问公用文件夹但失败了,因为该文件夹中没有名为 authors 的文件,也没有名为 public/authors 的路由。假设您的安装位于 http://localhost:8081/branch 中,您将希望转至 http://localhost:8081/branch/authors

【讨论】:

    【解决方案2】:

    您应该删除public $restful = true;,但NotFoundHttpException 没有问题

    // Path: app/controllers/AuthorsController.php
    class AuthorsController extends BaseController {
    
        // public $restful = true;
    
        public function getIndex () {
            return View::make('authors.index');
        }
    }
    

    根据您在下面给出的route

    Route::get('authors', 'AuthorsController@getIndex');
    

    如果您发出GET 请求,它应该可以工作,请确保您从浏览器的地址栏发出请求并且url 类似于yourdomain.dev/authorshttp://localhost/yourapp/authors。您也可以从命令提示符/终端(在您的项目目录中)运行以下命令:

    composer dump-autoload
    

    【讨论】:

    • 啊谢谢!我现在已经修好了,你怎么会说 remove public $restful = true; ?
    • 欢迎,是的,声明RESTful controllers 你不需要在控制器中使用public $restful = true;,它在version-3
    • 啊,好的,谢谢你说得通。另一个问题,你知道如何从 URL 中删除公共目录吗?
    • 最好的办法是使用虚拟主机,查看this answer of mine
    猜你喜欢
    • 2015-10-29
    • 2015-05-07
    • 2016-12-12
    • 2017-10-12
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多