脚本宝典收集整理的这篇文章主要介绍了php – 使用flash消息重定向回布局模板,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如果登录成功,我可以简单地使用return redirect :: back().
当凭据不正确并且我想使用flash消息重定向时,我的问题就开始了.
我知道我可以将wITh方法链接到Redirect,但是这会将数据发送到特定视图,而不是登录HTML所在的布局.
我可以像这样加载一个视图:
$this->layout ->with('flash',$message) ->content = View::make('index');
{{ $errors->has('email') ? 'Invalid Email Address' : 'Condition is false. Can be left blank' }}
如果有任何错误返回,这将显示一条消息.
然后在验证过程中你有…
$rules = array(check credentials and login here...); $validation = Validator::make(Input::all(),$rules); if ($validation->fails()) { return Redirect::to('LOGin')->with_errors($validation); }
这样……当你进入登录页面时,它会检查错误而不管是否提交,如果发现任何错误,它会显示你的消息.
编辑部分
用于处理Auth类..
这在你看来……
@if (Session::has('login_errors')) <span class="error">Username or password incorrect.</span> @endif
然后在你的身份……沿着这些方向……
$userdata = array( 'username' => Input::get('username'),'password' => Input::get('password') ); if ( Auth::attempt($userdata) ) { // we are Now logged in,go to home return Redirect::to('home'); } else { // auth failure! lets go back to the login return Redirect::to('login') ->with('login_errors',true); }
以上是脚本宝典为你收集整理的php – 使用flash消息重定向回布局模板全部内容,希望文章能够帮你解决php – 使用flash消息重定向回布局模板所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。