php Symfony\Component\HttpKernel\Exception\NotFoundHttpException Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23593892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony\Component\HttpKernel\Exception\NotFoundHttpException Laravel
提问by Harsh
I am trying to use RESTful controller. Here is my Route.php
:
我正在尝试使用 RESTful 控制器。这是我的Route.php
:
Route::resource('test', 'TestController');
Route::get('/', function()
{
return View::make('hello');
});
Here is my TestController.php
这是我的 TestController.php
<?php
class TestController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
return View::make('test.home');
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}
My app route is localhost/Test/public/
and it shows "You have arrived" message. But when I tried localhost/Test/public/test
It gives me "Symfony\Component\HttpKernel\Exception\NotFoundHttpException"
我的应用程序路线是localhost/Test/public/
,它显示“您已到达”消息。但是当我尝试时localhost/Test/public/test
它给了我“Symfony\Component\HttpKernel\Exception\NotFoundHttpException”
Here is my log:
这是我的日志:
[2014-05-11 14:29:59] production.ERROR: NotFoundHttpException Route: `http://localhost/Test/public/test` [] []
[2014-05-11 14:29:59] production.ERROR: exception 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException' in C:\wamp\www\test\bootstrap\compiled.php:5289
Stack trace:
#0 C:\wamp\www\test\bootstrap\compiled.php(4663): Illuminate\Routing\RouteCollection->match(Object(Illuminate\Http\Request))
#1 C:\wamp\www\test\bootstrap\compiled.php(4651): Illuminate\Routing\Router->findRoute(Object(Illuminate\Http\Request))
#2 C:\wamp\www\test\bootstrap\compiled.php(4643): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#3 C:\wamp\www\test\bootstrap\compiled.php(698): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#4 C:\wamp\www\test\bootstrap\compiled.php(679): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#5 C:\wamp\www\test\bootstrap\compiled.php(1136): Illuminate\Foundation\Application->handle(Object(Illuminate\Http\Request), 1, true)
#6 C:\wamp\www\test\bootstrap\compiled.php(7218): Illuminate\Http\FrameGuard->handle(Object(Illuminate\Http\Request), 1, true)
#7 C:\wamp\www\test\bootstrap\compiled.php(7815): Illuminate\Session\Middleware->handle(Object(Illuminate\Http\Request), 1, true)
#8 C:\wamp\www\test\bootstrap\compiled.php(7762): Illuminate\Cookie\Queue->handle(Object(Illuminate\Http\Request), 1, true)
#9 C:\wamp\www\test\bootstrap\compiled.php(10768): Illuminate\Cookie\Guard->handle(Object(Illuminate\Http\Request), 1, true)
#10 C:\wamp\www\test\bootstrap\compiled.php(640): Stack\StackedHttpKernel->handle(Object(Illuminate\Http\Request))
#11 C:\wamp\www\test\public\index.php(49): Illuminate\Foundation\Application->run()
#12 {main} [] []
I know this question has been asked many times. I had gone through many relevant threads but just can not figure out the solution.
我知道这个问题已经被问过很多次了。我经历了许多相关的线程,但就是想不出解决方案。
回答by Antonio Carlos Ribeiro
A NotFoundHttpException
exception in Laravel always means that it was not able to find a routerfor a particular URL. And in your case this is probably a problem in your web server configuration, virtual host (site) configuratio, or .htaccess configuration.
一个NotFoundHttpException
在Laravel例外总是意味着它无法找到路由器的一个特定的URL。在您的情况下,这可能是您的 Web 服务器配置、虚拟主机(站点)配置或 .htaccess 配置中的问题。
Your public/.htaccess should look like this:
您的 public/.htaccess 应如下所示:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
As you can see there is a condition in the first line IfModule mod_rewrite.c
, so if you don`t have mode_rewrite installed or enabled, all rewrite rules will fail and this
正如你所看到的,第一行有一个条件IfModule mod_rewrite.c
,所以如果你没有安装或启用 mode_rewrite,所有的重写规则都会失败,这个
localhost/Test/public/
Will work fine, but not this:
会正常工作,但不是这样:
localhost/Test/public/test
In other hand, this one should work too, because this is its raw form:
另一方面,这个也应该工作,因为这是它的原始形式:
localhost/Test/public/index.php/test
Because Laravel needs it to be rewritten to work.
因为 Laravel 需要重写它才能工作。
And note that you should not be using /public, your URLs should look like this:
请注意,您不应使用 /public,您的 URL 应如下所示:
localhost/Test/
This is another clue that your virtual host's document root is not properly configured or not pointing to /var/www/Test/public, or whatever path your application is in.
这是另一个线索,表明您的虚拟主机的文档根目录未正确配置或未指向 /var/www/Test/public,或您的应用程序所在的任何路径。
All this assuming you are using Apache 2.
所有这些都假设您使用的是 Apache 2。
回答by OZODJON AMINJONOV
Before my web.php was like below
在我的 web.php 像下面这样之前
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
Route::resource('roles','Admin\RoleController');
Route::resource('users','Admin\UserController');
});
Route::group(['prefix' => 'admin', 'middleware' => ['role:admin']], function() {
Route::resource('roles','Admin\RoleController');
Route::resource('users','Admin\UserController');
});
In url enterd
在输入的网址中
and get same error. The solution was :
并得到同样的错误。解决方案是:
Route::group(['middleware' => ['role:admin']], function() {
Route::resource('roles','Admin\RoleController');
Route::resource('users','Admin\UserController');
});
Remove 'prefix' => 'admin', as both Controllers are located in Admin folder
删除 'prefix' => 'admin',因为两个控制器都位于 Admin 文件夹中
回答by alexanderesmar
like Arjan Koole says, I had a similar error
就像 Arjan Koole 说的,我也有类似的错误
using:
使用:
Route::get('/performance/{$submit_type}/{$send_selected}/{$date_a}/{$date_b}', 'PerformanceController@calc');
instead of
代替
Route::get('/performance/{submit_type}/{send_selected}/{date_a}/{date_b}', 'PerformanceController@calc');
So be aware when you use {$stuff}
所以当你使用 {$stuff} 时要注意
回答by М.Б.
In my scenario, the problem was I've used an extra prefix slashlike:
在我的场景中,问题是我使用了一个额外的前缀斜杠,如:
Route::get('/plans', 'PayPalController@getPlansList')->name('paypal.plans');
instead of:
代替:
Route::get('plans', 'PayPalController@getPlansList')->name('paypal.plans');
回答by Pratik
I was getting the same error exception while one project was working but another project with same .htaccess file on same localhost was not working. Turns out since my project directory has capital letter in it, URL also should be capital for routing to work. localhost/minorweb/public/accountwas not working but localhost/minorWeb/public/accountwith W capital was working. so, if nothing seems to solve the problem, check your URL is matched with project directory with case.
当一个项目正在运行时,我遇到了相同的错误异常,但在同一本地主机上具有相同 .htaccess 文件的另一个项目不工作。事实证明,由于我的项目目录中有大写字母,因此 URL 也应该大写以便路由工作。localhost/minorweb/public/account不工作,但localhost/minorWeb/public/account与 W 资本工作。因此,如果似乎没有任何方法可以解决问题,请检查您的 URL 是否与项目目录匹配。
回答by Arjan Koole
I have found another situation where this error can occur, and that one has nothing todo with rewrites, for once. It's a very nasty typo :)
我发现了另一种可能发生此错误的情况,并且一次与重写无关。这是一个非常讨厌的错字:)
I had:
我有:
Route::get('replicas/item/{id}/{?stub}', ['uses' => 'ProductReplicasController@productview', 'as' => 'database.replicas.productview']);
Route::get('replicas/item/{id}/{?stub}', ['uses' => 'ProductReplicasController@productview', 'as' => 'database.replicas.productview']);
see the {?stub}, that caused this error with me, it needs to be {stub?} off course. But if you're new to Laravel (like me), that is very easy to miss and could take quite some time to figure out. :)
看到 {?stub},导致我出现这个错误,它当然需要 {stub?}。但是如果你是 Laravel 的新手(像我一样),这很容易被忽略并且可能需要很长时间才能弄清楚。:)
回答by pitney
another thing to check is your document root,
要检查的另一件事是您的文档根目录,
mine was:
我的是:
www/var
万维网/无功
and should be:
并且应该是:
www/var/mysite/public
www/var/mysite/public
Another reason why I hate web development
我讨厌 Web 开发的另一个原因