所以我想用一個登錄(登錄)表單和註冊(註冊)形式與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