Giter Site home page Giter Site logo

zf-annotated-forms's Introduction

#Installation

Add to composer.json

"phpro/zf-annotated-forms": "dev-master"

Add to application config

return array(
    'modules' => array(
        'Phpro\\AnnotatedForms',
        // other libs...
    ),
    // Other config
);

Configuration files

Copy module.zf-annotated-forms-global.dist.php to your application configuration autoload directory. You can adjust this file and set the default values. The annotated_forms can also be declared in your module config.

Form configuration

return array(
    'annotated_forms' => array(
        'form-key' => array(
            'initializers' => array(),
            'listeners' => array(),
            'cache' => null,
            'cache_key' => 'cached-form-key',
            'entity' => '',
        ),
    ),
);

initializers: Array of service manager keys, which return InitializerInterfaces. These initializers are used to inject dependencies in form elements.

listeners: Array of service manager keys, which return EventListenerAggregateInterface. These listeners can be used to adjust the form.

cache: Service manager key, which return Cache\StorageInterface. This cache storage is used to save parsed annotations. This can be left null if you do not want to be using cache.

cache_key: The cache key where the parsed configuration is being saved in the cache locator. This can be left null if you do not want to be using cache.

entity: The name of the class which contains the form annotations.

Load the form

You can now use the serviceManager to retrieve your form. In the config example above, you can use:

$serviceManager->get('form-key');

Configure cache

While configuring a cache storage, there are some things to keep in mind:

  • Disable the exceptions by default
  • Add a serializer
  • The ttl of the forms can be infinite if you clear the cache after building your application

Sample configuration:

'caches' => [
    'Cache\AnnotatedForms' => [
        'adapter' => [
            'name' => 'redis',
            'options' =>  [
                'namespace' => 'zf-annotated-forms',
                'server' => [
                    'host' => '127.0.0.1',
                    'port' => '6379',
                ],
                'ttl' => 86400 // 1 day
            ],
        ],
        'plugins' => [
            'exception_handler' => [
                'throw_exceptions' => false,
            ],
            'serializer',
        ],
    ],
],

zf-annotated-forms's People

Contributors

veewee avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.