3

I used doctrine2 in zf3, while connect multiple db caused error. Then following is my config in global.php

return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' => PDOMySqlDriver::class,
                'params' => [
                    'host'     => '127.0.0.1',
                    'user'     => 'root',
                    'password' => '123456',
                    'dbname'   => 'zf3.com',
                    'charset' => 'utf8',
                ]
            ],
            'orm_passport' => [
                'driverClass' => PDOMySqlDriver::class,
                'params' => [
                    'host'     => '127.0.0.1',
                    'user'     => 'root',
                    'password' => '123456',
                    'dbname'   => 'zf3.com.passport',
                    'charset' => 'utf8',
                ]
            ],
        ],
        'entitymanager' => [
            'orm_passport' => [
                'connection' => 'orm_passport',
            ]
        ],
    ],
];

And driver config in module.config.php as following:

'doctrine' => [
        'driver' => [
            __NAMESPACE__ . '_driver' => [
                'class' => AnnotationDriver::class,
                'cache' => 'array',
                'paths' => [__DIR__ . '/../src/Entity']
            ],
            'orm_passport' => [
                'drivers' => [
                    __NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
                ]
            ]
        ]
    ],

In my IndexController.php

 public function indexAction()
    {
        // Get recent users
        $users = $this->entityManager->getRepository(Users::class)
            ->findBy(['status'=>Users::ACTIVE_STATUS_NO],['timeCreated'=>'DESC']);

        //\Doctrine\Common\Util\Debug::dump($users);

        return new ViewModel([
            'users' => $users
        ]);
    }

The error message : The class 'Passport\Entity\Users' was not found in the chain configured namespaces Application\Entity

2
  • In which namespace is the content of the module.config.php file? Application, Passport? Commented May 12, 2017 at 20:23
  • i change my global.php , add some choices , it works Commented May 15, 2017 at 6:35

1 Answer 1

1

the following is my global.php

return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driverClass' => PDOMySqlDriver::class,
                'params' => [
                    'host'     => '127.0.0.1',
                    'user'     => 'root',
                    'password' => '123456',
                    'dbname'   => 'zf3.com',
                    'charset' => 'utf8',
                ]
            ],
            'orm_passport' => [
                'driverClass' => PDOMySqlDriver::class,
                'params' => [
                    'host'     => '127.0.0.1',
                    'user'     => 'root',
                    'password' => '123456',
                    'dbname'   => 'zf3.com.passport',
                    'charset' => 'utf8',
                ]
            ],
        ],
        'entitymanager' => [
            'orm_passport' => [
                'connection' => 'orm_passport',
                'configuration' => 'orm_passport',
            ]
        ],
        'migrations_configuration' => [
            'orm_passport' => [
                'directory' => 'data/DoctrineORMModule/Migrations',
                'name' => 'Doctrine Database Migrations',
                'namespace' => 'DoctrineORMModule\\Migrations',
                'table' => 'migrations',
                'column' => 'version',
            ],
        ],
        'configuration' => [
            'orm_passport' => [
                'metadata_cache' => 'array',
                'query_cache' => 'array',
                'result_cache' => 'array',
                'hydration_cache' => 'array',
                'driver' => 'orm_passport',
                'generate_proxies' => true,
                'proxy_dir' => 'data/DoctrineORMModule/Proxy',
                'proxy_namespace' => 'DoctrineORMModule\\Proxy',
            ]
        ],
        'authentication' => [
            'odm_passport' => [],
            'orm_passport' => [
                'objectManager' => 'doctrine.entitymanager.orm_passport',
            ],
        ],
        'authenticationadapter' => [
            'odm_passport' => true,
            'orm_passport' => true,
        ],
        'authenticationstorage' => [
            'odm_passport' => true,
            'orm_passport' => true,
        ],
        'authenticationservice' => [
            'odm_passport' => true,
            'orm_passport' => true,
        ],
    ],
];

it works!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.