脚本宝典收集整理的这篇文章主要介绍了php – 从Symfony2中的嵌入式控制器重定向,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
// index.html.twig {% block header %} {% if app.session.get('LOGgedin') is null%} <div class="linear_form_holder"> {% render "AppBaseBundle:Core:login" %} </div> {% endif %} {% endblock %}
现在,在登录控制器中,我使用这个:
public function loginAction(Request $request) { if ($password == $record->getpassword()) { /* then set the session VARiables */ $session->set('loggedin','1'); $session->set('username',$record->getUsername()); $session->set('userid',$record->getId()); /* and grant access to the PRofile */ return $this->redirect($this->generateUrl('home'),301); } else return $this->redirect($this->generateUrl('main_page'),301); }
但是,我收到此错误:
在呈现模板期间抛出异常(“呈现时出错”http://localhost/web/app_dev.PHP/“(状态代码为301).”)在AppBaseBundle:Core:index.html.twig at第6行.
解决方案是:
1.让您在子模板中创建的表单发布到您的父控制器. (表单仍然可以在不同的控制器中创建,没问题)
2.在父控制器中检查您的请求以捕获来自子控制器的信息,并检查您的子模板表单的信息是否进入.
例如:
$myPostInfo = $request->request->all() if(isset($myPostInfo['acme_userbundle_login'])) { die('form has been submITted'); // here you can do the stuff one would do on a committed form }
对于登录,最好将其添加到您的基本模板,但是当您有AJAX调用的表单时,这是我使用的解决方案.
祝好运
任何问题?让我发布.
以上是脚本宝典为你收集整理的php – 从Symfony2中的嵌入式控制器重定向全部内容,希望文章能够帮你解决php – 从Symfony2中的嵌入式控制器重定向所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。