2010-04-23 71 views
0

我試圖在登錄和註冊表單中加入相同的操作。這就是我想:Symfony:在同一頁面中加入兩個表單

模塊/ miembros /的actions.class.php

public function executeAux(sfWebRequest $request) 
    { 
     // I execute this action 

    } 

模塊/ miembros /模板/ auxSuccess.php

<?php include_component('sfGuardRegister', 'register'); ?> 
<?php include_component('sfGuardAuth', 'signin'); ?> 

模塊/ miembros /組件。 class.php

public function executeSignin($request) 
{ 

    if ($request->isMethod('post') && ($request- 
>getParameter('submit')=='signin')){ 

    $this->form->bind($request->getParameter('login')); 
    if ($this->form->isValid()){ 
     $this->getController()->getActionStack()->getLastEntry()->getActionInstance()->redirect('@home'); 
    } 
    } 

} 

模塊/ miembros /模板/ _signin.php

<form action="<?php echo url_for('miembros/aux?submit=signin') ?>" 
method="post"> 

     <?php echo $form['email_address']->renderLabel() ?> 
     <?php echo $form['email_address'] ?> 
... 

它工作正常,但我想知道你是否有其他的選擇。例如,我不喜歡該行: $ this-> getController() - > getActionStack() - > getLastEntry() - > getActionInstance() - >重定向('@home');

問候

哈維

回答

1

你不應該在你的組件處理表單,你應該這樣做在你的行動。這些組件意味着可以被包含在其他模板中的可重用視圖(類似於partials,但是有一些代碼支持它們以維持更復雜的數據檢索)。如果您想在組件中顯示錶單以便重用它,您可以,但您應該在另一個操作中處理表單。

+0

我有一個基於您的意見的新建議。 – ziiweb 2010-04-23 16:56:27

1

感謝matei的評論這是我的新建議。你現在的意見是什麼?

模塊/ miembros /動作/的actions.class.php

public function executeAux(sfWebRequest $request) 
{ 
    return $this->renderPartial('aux'); 
} 

模塊/ miembros /模板/ _aux.php

if(!isset($form_register)){ 

    $form_register = new sfGuardFormRegisterByOthers(); 
} 

include_partial('sfGuardRegister/register', array('form' => $form_register)); 


if(!isset($form_signin)){ 

    $form_signin = new sfGuardFormSigninByEmail(); 
} 

include_partial('sfGuardAuth/signin', array('form' => $form_signin)); 

模塊/ sfGuardAuth /模板/ _signin

<form action="<?php echo url_for('sfGuardAuth/signin') ?>" method="post"> 

modules/miembros/sfGuardAuth/actions.class.php

if ($this->form->isValid()) 
{ 
    //... 

}else{ 

    return $this->renderPartial('miembros/aux', array('form_signin' => $this->form)); 

} 

它也有效。

Javi

+0

自從這篇文章已經很長時間了,但是愛爾蘭有一個問題,我正在與symfony 1.4一起開發項目嗎? 你能否向我解釋一下如何渲染一個不包含模板的部分? – 2013-12-19 15:30:44

相關問題