简体   繁体   中英

What does PURE CONFIGURATION mean in ZF2?

I was going through Form Creation in ZF2 and I read the following statement. " You can create the entire form, and input filter, using the Factory. This is particularly nice if you want to store your forms as pure configuration ; you can simply pass the configuration to the factory and be done." Can anybody tell in detail what does PURE CONFIGURATION mean?

It means that you're able to store your forms within any config file, eg module.config.php and then pass this configuration key into the form factory. This is similar what has been done in ZF1 often times, too.

This whole process is done through the Zend\\Form\\Factory and if you check out the source code you'll see that you could pass it the following array to create a Form

$someConfig = array(
  'form-key-name' => array(
    'fieldsets' => array(
        'fieldset_1' => array(
            'elements' => array(
                'elem_x' => array(/** Single Form-Element Array*/)
            ),
            'fieldsets' => array(
                'fs_y' => array(/** More Sub-Fieldset Array*/)
            ),
        )
    )
  )
);

Note that this example is quite incomplete (missing name => foo ), hydrator configuration, inputFilter configuration, etc... but as it is this should give you a idea of what's meant by that statement.

Using the above-mentioned configuration then you can pass it to the factory

$factory = new \Zend\Form\Factory();
$form    = $factory->createForm($someConfig['form-key-name']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM