Now the product fieldset : We pass here the category manager and attribute service manager as parameters.
As an example of use we will take a Recipe as a product which is of one type (or category, ie : breakfast…), the recipe uses several ingredients (item entity) and as main attribute we will assume one ingredient contains gluten : Time to code now, we will start with our entities and then attach services to deal with those entities – we name the module : Fieldset.
Category entity (ex : type of recipe) The advantage of using Fieldsets is that you can include them in different forms and separate coding between classes.
Packagist Link Git Hub Link We're not quite done, for all of this to work you have to invoke your Form properly.
You already know how to add elements to a form and attach filters and validators to them, but often you will need to add new elements dynamically or add several elements with the same name.
To bring those fieldsets into action, we attach them to the form as follow : namespace Fieldset\Form; use Zend\Form\Form; use Zend\Form\Element; use Fieldset\Form\Product Fieldset; use Zend\Hydrator\Class Methods; // One product is defined by a category and list of items class Product Form extends Form To retrieve and add attributes and categories we use services managers.
Here we don’t use Doctrine neither factories but in a later tutorial we will implement Doctrine 2 within ou Fieldset demo example.
For now you will find the https://docs.zendframework.com/tutorials/getting-started/modules/ We won’t implement database connection inside this version of the tutorial but a service manager so you can add Doctrine 2 integration later on.
For a full understanding of what’s being involved here, you may browse the documentation on Zend framework about fieldsets and here for form collections.
Here's where you and I probably reach the same conclusion: Damn that's a lot of boilerplate!