我目前正在使用 Laravel 4 和 Sentry 2 开发一个非常简单的身份验证系统,并启用了限制。也就是说,当用户因挂起而尝试登录时引发异常时,应将他重定向回登录视图,并显示一条消息,指出"此用户已挂起 $time 分钟"。
问题是:我无法同时向视图返回变量和文本消息。也许我错过了正确的语法,我不知道。这让我发疯,因为我需要为许多其他例外情况这样做。这似乎是一个新手问题,解决方案应该非常简单。
这是我代码中很重要的部分:
catch (Cartalyst'Sentry'Throttling'UserSuspendedException $e)
{
$throttle = Sentry::findThrottlerByUserLogin(Input::get('username'));
$time = $throttle->getSuspensionTime();
return Redirect::route('account-sign-in-get')
->with('message','This user has been suspended for [$time] minutes.');
}
提前谢谢。
只需替换
->with('message','This user has been suspended for [$time] minutes.');
跟
->with('message', "This user has been suspended for {$time} minutes.");
到底发生了什么:
在 PHP 中,当您在字符串周围使用单引号时,它不会解析嵌入在该字符串中的变量,但是当您使用双引号时,它会解析它。