开发者

Can I do more than one form for the same model class in symfony?

Well, imagine that we have a register form of a class Customer and we only ask three fields (name,surname,email) and after, when this user logged first time we want to complete this information.

First, we have in lib/form/doctrine a file called 'CustomerForm.class.php' wich is generated automatic on command line. In this file we 'setup' only 3 fields and validators and if we wanna use we do something like that:

$this->form = CustomerForm();

Second, we create manual another form named 'CustomerFormStep1.class.php' where we c开发者_C百科an setup for validate the other fields. But when we do..

$this->form = CustomerFormStep1();

it returns error: Fatal error: Class 'CustomerFormStep1' not found

What is wrong?

Thanks.


Assuming you have the form defined as:

class CustomerFormStep1 extends sfForm

or similar (sfFormDoctrine etc), and named correctly like you say (CustomerFormStep1.class.php) and in lib/form, then Symfony should just pick the definition up fine. Did you clear the cache after creating and placing it in the right place? (symfony cc).


Create the new CustomerFormStep1 class as @richsage instructed. Then, in your actions you can write something like:

public function executeLogin(){
 //before login
 $this->form = new CustomerForm();
}

public function executeLoggedIn(){
 $this->form = new CustomerFormStep1();
 //other steps
}


Haven't you read the tutorial? Extending forms is perfectly described in context with reh admin generator and can of course be applied to any case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜