【问题标题】:Redirecting to the same route /user/{{username}} Laravel 4+重定向到相同的路由 /user/{{username}} Laravel 4+
【发布时间】:2014-04-12 16:05:34
【问题描述】:

我是新手,想在过滤器之前进行过滤,它将检查我想要的内容并将错误或成功的重定向返回到相同的/user/{{username}} 配置文件。

所以这是我在函数之前的过滤器

Route::filter('test', function()
{

     $param = Request::segment(2);

        if($para = 'username')
        {
        Session::flash('error', 'blabla!'); 
        return Redirect::route('profile-public');
        }
            else
            {
                Session::flash('secces', 'xxx!');
                return Redirect::route('profile-public');   
            }

});

这是我的路线

Route::group(array('before' => 'test'), function() {

Route::get('/user/{username}', array('as' => 'profile-public','uses' => 'ProfileController@user')); });

还有我的 ProfileController 公共功能

public function user($username)
{
    $user = User::where('username', '=', $username);
    if($user->count()){
        $user = $user->first();
    return View::make('profile.user')
            ->with('user', $user);
    }

    return App::abort(404);
}

所以我的问题是如何让这些重定向工作,我试图搜索谷歌等,但我找不到任何答案。对不起,这是我在这里的第一篇文章,对不起我的英语。 示例转到 /user/admin 的公共配置文件 --> 过滤检查 --> 错误或成功重定向到 /user/admin。

【问题讨论】:

  • 有一个无限循环,你的过滤器一次又一次地重定向到 profile-public 路由。

标签: php redirect parameters laravel


【解决方案1】:

这里不需要重定向,只需使用此过滤器即可:

Route::filter('test', function()
{
    $param = Request::segment(2);

    if ($para = 'username')
    {
        Session::flash('error', 'blabla!');
    }
    else
    {
        Session::flash('secces', 'xxx!');
    }
});

【讨论】:

    猜你喜欢
    • 2016-01-16
    • 2013-11-22
    • 2013-09-19
    • 2018-10-31
    • 2015-11-06
    • 2013-07-19
    • 1970-01-01
    • 2013-09-14
    • 2017-06-19
    相关资源
    最近更新 更多