Using ZF2 components without entire MVC process

2019-08-09 04:07发布

问题:

How feasible is it to use the Zend Framework 2 components without using the MVC process? For example I love the forms / validation and ACL elements but am not sure if that is actually possible without the whole MVC system?

As a framework ZF2 is very slow (although I think its a very good system) so would like to encourage its use without the whole package. Thanks.

回答1:

Yes. Zend Form component has a separate repository and it can be used in any application as a component with help of composer. (I'm assuming that you're using composer and your application also uses composer's autoloader) It requires only InputFilter and Stdlib components.

You can try easily. Open your command line:

$ cd /path/to/an-empty-folder

Create a composer.json file with the content below

{
    "name": "Form Demo App",
    "require": {
        "php": ">=5.4",
        "zendframework/zend-form": "2.3.*@dev"
    }
}

and after type

$ composer update

Following dependencies will be installed automatically into the vendor directory and composer.lock will be created :

Loading composer repositories with package information
Installing dependencies (including require-dev)
  - Installing zendframework/zend-stdlib (2.3.3)
    Downloading: 100%         

  - Installing zendframework/zend-validator (2.3.3)
    Downloading: 100%         

  - Installing zendframework/zend-filter (2.3.3)
    Downloading: 100%         

  - Installing zendframework/zend-inputfilter (2.3.3)
    Downloading: 100%         

  - Installing zendframework/zend-form (2.3.3)
    Downloading: 100% 

From performance viewpoint, ZF2 is not very slow. You just need to do couple of things on production environment to run your application much more more performant.