所以我想用一个登录(登录)表单和注册(注册)形式与Symfony2的页面。我想知道什么是实现这个目标的最好方法?Symfony2在一个页面上的多种形式
我考虑过设置表格属性action="/pathToMyFormProcess"
,但是接着我遇到了一个问题:我想在该动作中显示相同的模板(HTML页面)。但是“/ pathToMyFormProcess”将在不同模板的不同动作中被调用。就像在每个页面上包含或呈现的登录表单一样。我可以为每个模板创建一个新的路径和行动。但正如这个例子表明这将是非常令人沮丧的:
我注册的行动将是:
public function signupAction() {
$loginForm = $this->get('loginform'); // Get the login form
$signUpForm = $this->get('signupform'); // Get the signup form
$loadData = ... /* Loading data needed for this page (could be last visitors,
countries, some information from database that should be displayed on the page) */
return // SIGNUPTEMPLATE - array (forms and data)
}
这时如果有人使用的登录表单,将它们发送到例如/注册/登录用行动在loginAction中例如SignupController。
public function signupAction() {
$loginForm = $this->get('loginform'); // Get the login form
$handler = $this->get('loginhandler'); // Get the handler
$process = $handler->process(); // Process the request, try to log in basicly.
if($process) {
return // redirect or something - no problem
}
// Loading again, writing exact same code as signupAction()
$signUpForm = $this->get('signupform'); // Get the signup form
$loadData = ...
return // SIGNUPTEMPLATE - array (forms and data)
}
所以我想知道如果你有什么更好的想法如何实现这一目标?
这是一个链接,只能回答,应该是一个评论:-) – Jimbo 2015-02-09 21:59:38