LARAVEL 4.2 NotFoundHttpException,其中我的视图名称是正确的


LARAVEL 4.2 NotFoundHttpException where my view name is correct

问题出在哪里?我的路线是正确的,视图名称也是正确的,但我无法显示我的视图。为什么?

//route.php

Route::get('register', 'HomeController@register');

//controller.php

class HomeController extends 'BaseController {
public function index() {
    return View::make('index');
}
public function register() {
    return View::make('register');
}
}

//错误日志

[2015-11-13 09:42:21] production.ERROR: exception     'Symfony'Component'HttpKernel'Exception'NotFoundHttpException' in     C:'wamp'www'x'bootstrap'compiled.php:5751
Stack trace:
#0 C:'wamp'www'x'bootstrap'compiled.php(5073):     Illuminate'Routing'RouteCollection->match(Object(Illuminate'Http'Request))
#1 C:'wamp'www'x'bootstrap'compiled.php(5061): Illuminate'Routing'Router->findRoute(Object(Illuminate'Http'Request))
#2 C:'wamp'www'x'bootstrap'compiled.php(5053): Illuminate'Routing'Router->dispatchToRoute(Object(Illuminate'Http'Request))
#3 C:'wamp'www'x'bootstrap'compiled.php(715): Illuminate'Routing'Router->dispatch(Object(Illuminate'Http'Request))
#4 C:'wamp'www'x'bootstrap'compiled.php(696): Illuminate'Foundation'Application->dispatch(Object(Illuminate'Http'Request))
#5 C:'wamp'www'x'bootstrap'compiled.php(7825): Illuminate'Foundation'Application->handle(Object(Illuminate'Http'Request), 1, true)
#6 C:'wamp'www'x'bootstrap'compiled.php(8432): Illuminate'Session'Middleware->handle(Object(Illuminate'Http'Request), 1, true)
#7 C:'wamp'www'x'bootstrap'compiled.php(8379): Illuminate'Cookie'Queue->handle(Object(Illuminate'Http'Request), 1, true)
#8 C:'wamp'www'x'bootstrap'compiled.php(11088): Illuminate'Cookie'Guard->handle(Object(Illuminate'Http'Request), 1, true)
#9 C:'wamp'www'x'bootstrap'compiled.php(657): Stack'StackedHttpKernel->handle(Object(Illuminate'Http'Request))
#10 C:'wamp'www'x'index.php(49): Illuminate'Foundation'Application->run()
#11 {main} [] []

我看到您正在使用compiled.php,您尝试更新文件了吗?这可以使用命令php artisan optimize来完成。

更新:你能把类HomeController放在同一目录中一个名为HomeController.php的文件中吗?这就是创建所有类的方式,因为composer将以这种方式加载它们。

之后,再次更新compiled.php

更新:

我想我有点搞不懂这个问题

If you are trying to call your route from the controller then, you can user this answer.

在这段代码中,您调用的是视图文件(registerblade.php),而不是路由。

public function register() {
    return View::make('register');
}

如果你想呼叫一条你需要做的路线:

public function register() {
    return Redirect::to('register');
}

如果你将你的路线定义为命名路线,那将是一个加分项:

Route::get('register', ['as' => 'register', 'use' => 'HomeController@register']);

然后你也可以用它的名字来称呼这条路线:

return Redirect::route('register');

If you are trying to call register function of HomeController, then you should check few things:

  • 首先确保控制器文件的名称为HomeController.php

  • 然后尝试通过composer update命令更新composer

  • 然后通过composer dumpautoload命令加载所有类

  • 最后通过php artisan cache:clear 清除缓存

希望这些事情能解决你的问题。