Laravel 错误 Symfony\Component\HttpKernel\Exception\NotFoundHttpException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24365374/
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
Laravel error Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
提问by Mik
I have read other questions in this forum to fix this problem, but nothing helped me.
我已阅读本论坛中的其他问题来解决此问题,但没有任何帮助。
I'm receiving this error only in one folder in other folder laravel works perfect no errors. Error is:
我仅在其他文件夹中的一个文件夹中收到此错误,laravel 完美无误。错误是:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
The code i using. homa.blade.php
我使用的代码。刀片.php
<section>
<h2><a href="{{ URL::action('post-show', $post->slug) }}">{{ $post->title }}</a></h2>
{{ Markdown::parse(Str::limit($post->body, 300)) }}
<a href="{{ URL::action('post-show', $post->slug) }}">Read more →</a>
</section>
routes.php
路由文件
Route::get('/posts/{$slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
and controller is PostController.php
控制器是 PostController.php
<?php
class PostController extends BaseController {
public function getShow($slug) {
echo 'Tets';
}
}
This is all my code nothing more.
这就是我的全部代码。
采纳答案by The Alpha
Actually you should use (Remove $
from {$slug}
):
实际上你应该使用 (Remove $
from {$slug}
):
Route::get('/posts/{slug}', array(
'as' => 'post-show',
'uses' => 'PostController@getShow'
));
Also change:
也改变:
<a href="{{ URL::action('post-show', $post->slug) }}">Read more →</a>
To this:
对此:
<a href="{{ URL::route('post-show', $post->slug) }}">Read more →</a>
Or use route
helper function:
或者使用route
辅助函数:
<a href="{{ route('post-show', $post->slug) }}">Read more →</a>
回答by Damien Pirsy
URL::action
(as the name implies) expects an action, not a route name as you're passing.
URL::action
(顾名思义)期望一个动作,而不是您经过时的路线名称。
public string action(string $action, mixed $parameters = array(), bool $absolute = true)
公共字符串动作(字符串 $action,混合 $parameters = array(), bool $absolute = true)
You should use route():
你应该使用路由():
URL::route('post-show', array($post->slug))
public string route(string $name, mixed $parameters = array(), bool $absolute = true, Route $route = null)
公共字符串路由(字符串 $name,混合 $parameters = array(), bool $absolute = true,Route $route = null)