I see in the options for embedRelation you can pass a form class, so I assumed I could simple set a new form and modify it as desired then pass that as the class to embedRelation and voila my form would look/Act as I desire. Not the case so how do I do it!?
Example From magicForm.class.php:
function configure()
{
$magicForm = new magicForm();开发者_StackOverflow
unset($magicForm['fieldName']);
$this->embedRelation('Magic',$magicForm);
}
I would expect that this would embed a nifty form MINUS the 'fieldName' field, but it does not, an entire form is embeded with no changes.
So how do I customize a form before embeding it, and not useing embedForm which the above example works perfectly for?
embedRelation
takes the name of the Form class not an instance of the form itself, it then basically does all the inside the medo of creating an instance of tht class and setting it up. If you want to modify the form after that you need to do so by accessing the various schema objects like:
function configure()
{
$this->embedRelation('Magic','magicForm');
unset($this['Magic']['fieldName']);
$this->getEmbeddedForm('Magic')
->widgetSchema['anotherField']
->setOption('class', 'some_class');
//etc..
}
For what its worth i never use embed relation... i just do it with embedForm
as you mentioned.
精彩评论