所以我想用 Symfony2 制作一个带有登录(登录)表单和注册(注册)表单的页面。我想知道实现这一目标的最佳方法是什么?
我考虑过设置 form 属性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 )
}
然后,如果有人使用登录表单,它会将它们发送到例如 /signup/login,例如 SignupController 中的操作 loginAction。
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 )
}
所以我想知道您是否对如何实现这一目标有更好的想法?