ZF2 + doctrine without composer

后端 未结 3 1469
野趣味
野趣味 2020-12-21 16:37

I have a working ZF2 (skeleton) application and want to integrate Doctrine.

I have downloaded the 2 modules (DoctrineModule and DoctrineORMModule) from github as I\'

相关标签:
3条回答
  • 2020-12-21 16:50

    Try to edit the following method in the Module.php of the Application module:

    public function getAutoloaderConfig()
    {
        return array(
            'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                    __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                    'Doctrine' => //Path where your doctrine dist resides
                ),
            ),
        );
    }
    

    There is no need to define autoloading configuration for DoctrineModule and DoctrineORMModule because this are ZF2 modules and are providing autoloading configuration already.

    0 讨论(0)
  • 2020-12-21 16:55

    DoctrineORMModule does not explicitly support autoloading without composer (since it's a mess).

    As of current (0.7.*) version of DoctrineORMModule, the required packages are following:

    • doctrine/common (2.3.0)
    • doctrine/dbal (2.3.2)
    • symfony/console (v2.1.7)
    • doctrine/orm (2.3.2)
    • doctrine/doctrine-module (0.7.*)
    • doctrine/doctrine-orm-module (0.7.0)

    What you can do is defining all the autoloading namespaces in init_autoloader.php in your skeleton application (explaining the mess). The code to replace is the part about the autoloader factory:

    Zend\Loader\AutoloaderFactory::factory(array(
        'Zend\Loader\StandardAutoloader' => array(
            'autoregister_zf' => true,
            'namespaces' => array(
                'Doctrine\Common'   => __DIR__ . '/vendor/doctrine/common',
                'Doctrine\DBAL'     => __DIR__ . '/vendor/doctrine/dbal',
                'Symfony\Console'   => __DIR__ . '/vendor/symfony/console',
                'DoctrineModule'    => __DIR__ . '/vendor/doctrine/doctrine-module',
                'DoctrineORMModule' => __DIR__ . '/vendor/doctrine/doctrine-orm-module',
            ),
        ),
    ));
    

    You will have to configure the various git submodules on your own

    As of version 0.8.* of the modules, the dependencies will increase quite a bit because of how doctrine/common was splitted recently, so consider finding a solution to start using composer or you will just be delaying huge problems in future.

    This solution should work for now.

    0 讨论(0)
  • 2020-12-21 17:10

    Form annotations require Doctrine\Common, which contains an annotation parsering engine. The simplest way to install Doctrine\Common is if you are using Composer; simply update your composer.json and add the following line to the require section:

    "doctrine/common": ">=2.1", Then run php composer.phar update to install the dependency.

    If you’re not using Composer, visit the Doctrine project website for more details on installation.

    0 讨论(0)
提交回复
热议问题