有什么问题?我的路线是正确的,视图名称是正确的但我无法显示我的视图。为什么呢?
// 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} [] []
答案 0 :(得分:0)
我发现您使用的是compiled.php
,您是否尝试过更新文件?
这可以使用命令php artisan optimize
完成。
<强>更新强>
您可以将类HomeController
放在同一目录中名为HomeController.php
的文件中吗?这就是所有类的创建方式,因为composer会以这种方式加载它们。
在此之后,再次更新compiled.php
。
答案 1 :(得分:0)
<强>更新强>
我觉得我很难理解这个问题。
If you are trying to call your route from the controller then, you can user this answer.
在这段代码中,你正在调用一个视图文件(register.blade.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 dumpautoload
命令
最后按php artisan cache:clear
希望这些事情可以解决你的问题。