【问题标题】:Laravel: Redirect::to() in routes.php not workingLaravel:routes.php 中的 Redirect::to() 不起作用
【发布时间】:2015-05-31 18:00:14
【问题描述】:

在 routes.php 中,我在所有路由上都有这段代码:

# Lang::get('routes.page') = 'page';
if (preg_match('/\\/'.Lang::get('routes.page').'-[0-9]+/i',
    $_SERVER['REQUEST_URI'], $matches)) {
    if (isset($matches[0]) and strtolower($matches[0]) !== $matches[0]) {
        $url = str_ireplace(
            '/'.Lang::get('routes.page').'-', 
            '/'.Lang::get('routes.page').'-',
            $_SERVER['REQUEST_URI']
        );
        return Redirect::to($url, 301);
    }
}

这给了我错误:

异常处理程序中的错误:未定义路由 [内容]。 (查看:/path/to/app/views/view.blade.php)(查看:/path/to/app/views/view.blade.php)在/path/to/vendor/laravel/framework/src/照亮/路由/UrlGenerator.php:231

这是 Laravel 4.2。为什么会出现此错误?

【问题讨论】:

  • 您的路线文件中有Route::get('content', ...) 或类似名称吗?
  • 不,不在路线中。而且我没有在“return”运算符上方的代码中包含这个刀片模板文件。

标签: php laravel laravel-4


【解决方案1】:

“views/view.blade.php”中存在错误,但不在您的路线中。 可能是这样的

// ....
//
{{route('content')}}
// [or]
{{URL::route('content')}}
// ....

【讨论】:

  • “views/view.blade.php”中没有错误。我有“{{ URL::route('content') }}”,它在我的“return”命令下方的 routes.php 中定义。所以我无法解释为什么 Laravel 会尝试包含这个刀片文件,因为它没有在重定向代码上方的任何地方使用。
  • 将“{{ URL::route('content') }}”更改为“{{ URL::to("content") }}”。
猜你喜欢
  • 2020-11-12
  • 2022-01-15
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多