Thanks to @Hikaru-Shindo I looked into AnnotationForms
which seem to be the best available as a work-around for ModelForms
. But the example shown here doesn't work for me.
use Zend\Form\Annotation\AnnotationBuilder;
$builder = new AnnotationBuilder();
$form = $builder->createForm('User');
Looking at this code I wonder where the AnnotationBuilder
knows where to look for this user form. Especially because in the annotation in the form def there is a lowercase 'user'
@Annotation\Name("user")
I put the form def code into 'MyModule/Form/UserForm.php' and the lower code into my Controller. Is this the right way?
Had the same problem. The solution is a mindbreaker. Took me long time to find out. The problem lies in the first line of your annotation code.
This line is normally used for commenting your annotation code, but allmost everybody leaves it empty. Normally no issues, but this is somehow causing problems in the form annotations. You should either add some comment, add a space, or move your first line of code up. So:
or start like this:
Don't ask me why this is happening, found the solution somewhere online. As I understood the bug has been reported.
This could be your entity (and form definition) for a user entity (shortend version):
And to use this form:
So the builder needs the fully qualified name of your definition class. The name you set using the annotations is the name of the form used for example to create the form's id attribute.
If you have a use statement for it you could also abond the namespace: