V
V
Vlad Sharikov2014-05-09 02:15:54
Doctrine ORM
Vlad Sharikov, 2014-05-09 02:15:54

How to work with Doctrine ORM on the command line, or what should cli-config.php look like?

Windows 8.1, ZendFramework 2

Hi I'm running
com. Windows line, go to the zf2 project directory. From the root of the directory I run the command:
php ./vendor/doctrine/orm/bin/doctrine orm:*- instead of an asterisk, a command understandable by Doctrine (validate/create, etc.).
The result of running the command above is:

F:\Server\domains\zf2-skeleton>php ./vendor/doctrine/orm/bin/doctrine orm:valida
te-schema
You are missing a "cli-config.php" or "config/cli-config.php" file in your
project, which is required to get the Doctrine Console working. You can use the
following sample as a template:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;

// replace with file to your own project bootstrap
require_once 'bootstrap.php';

// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();

return ConsoleRunner::createHelperSet($entityManager);

We read what they write to us and create a file config/cli-config.phpwith the appropriate content:
<?php
use Doctrine\ORM\Tools\Console\ConsoleRunner;

// replace with file to your own project bootstrap
require_once 'bootstrap.php';

// replace with mechanism to retrieve EntityManager in your app
$entityManager = GetEntityManager();

return ConsoleRunner::createHelperSet($entityManager);

1. We are told to change the file bootstrap.phpto our own. Do I understand correctly that in zf2 the autoloader (bootstrap) is a file init_autoloader.phpin the root of the project? I have installed it for now, but there is one more problem anyway.
2. Second point: I need to get the EntityManager of my Zf2. The question is how to get it? Googled, but there are a lot of options and, since I'm new (noob, bottom ... - substitute my own) in zf2, I don't know which one is right and how to do it right.
For example, I found this:
$this->getServiceLocator()->get('doctrine.entitymanager.orm_default');

But you can work with this only in a method of some class or function and at the same time pass something into it from which we will pull out em. ServiceLocator $sl some probably. Again, this requires some kind of init function or xs. In general, the question is how to do it.
PS: in general, it is said everywhere that in order to work with DoctrineORM in this way, you need to use a slightly different command:
php vendor\bin\doctrine-module orm:validate-schema
- but in my case, this command gives something like this:
<?
require_once __DIR__ . '/src/MyZfcAdmin/Module.php';
PHP Fatal error:  Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (MyZfcAdmin) could not be initialized.' in F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php:189
Stack trace:
#0 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(163): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php(90): Zend\ModuleManager\ModuleManager->loadModule('MyZfcAdmin')
#2 [internal function]: Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\ModuleManager\ModuleEvent))
#4 F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\Ev in F:\Server\domains\zf2-skeleton\vendor\zendframework\zendframework\library\Zend\ModuleManager\ModuleManager.php on line 189

At the same time, the site opens without problems, the myZfcAdmin module does its job and works as it should.
I'm talking about this. I’m getting a crutch now I’m inserting ... Maybe it’s worth sorting out the work of the team php vendor\bin\doctrine-module orm:validate-schema, and not making a crutch?
So.com didn't help much with this, maybe I'll find something useful here.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gusakov, 2014-05-09
@hell0w0rd

There is a module for zf, official.
https://github.com/doctrine/DoctrineORMModule

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question