【发布时间】:2012-01-23 11:25:58
【问题描述】:
我有两个控制器,比如说 loginAction() 和 registerAction 嵌入到索引页面 (index.html.twig) 中,如下所示:
// 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);
}
但是,我收到了这个错误:
在 AppBaseBundle:Core 中渲染模板时抛出异常(“渲染“http://localhost/web/app_dev.php/”时出错(状态码为 301)。”):第 6 行的 index.html.twig。
如何在嵌入式控制器中进行重定向?
【问题讨论】:
-
您认为嵌入式控制器应该如何处理重定向?
-
我不确定在您的树枝模板中使用“渲染”功能。这里的意图是什么?当你到达你的 twig 模板时,你应该输出 html,如果你需要重定向,你应该在 之前 你到达这个阶段。在我看来,您正试图从 within 您的树枝模板重定向 - 这是正确的吗?
-
@kissmyface :是的,我认为这是正确的......(虽然我没有那样看)
-
或者,有没有更好的方法将登录表单嵌入到索引页面中?