Doctrine 2 Console Tool says: you are missing "cli-config.php" or "config / cli-config.php"

I ran the console console tool:

$ php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create --dump-sql 

I got this instead of the expected functionality:

 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); 

Questions:

  • I am on ZF2 and there is no file named bootstrap.php
  • I am new to ZF2, so I don’t know what my entityManager is and what should I put for GetEntityManager

How do I do this job?

+8
source share
2 answers

Easy way

Use the Doctrine module:

vendor/bin/doctrine-module orm:schema-tool:create --dump-sql

+11
source

Hard way

You need to write two files: bootstrap.php and cli-config.php

Why should I write two files, yes?

Doctrine documents will instruct you to do this.

Where does it say that?

Here:

In cli-config find the code

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

Here GetEntityManager() not part of any library or code, it is your own custom method that Doctrine offers you to write yourself, where this method is what returns the instance of Doctrine\ORM\EntityManager . I think the message of the Doctrine could be clearer in this part.

I still can not do this, Documents are too hard, help!

If your configuration has too many layers, that is, you are trying to develop Doctrine with ZF2 or Symphony, find out where Doctrine ends where the framework starts, etc. Try to configure Doctrine yourself in a separate container for testing, following the Doctrine docs, without using any framework, everything should become very very clear.

-

Here is what I did for my Doctrine config. I decided to create 3 files for more flexibility and put them in my ./config folder in my Zend folder structure.

Firstly, I have cli-config.php

 use Doctrine\ORM\Tools\Setup; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Console\ConsoleRunner; require 'config/bootstrap.php'; $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); $entityManager = EntityManager::create($dbParams, $config); return ConsoleRunner::createHelperSet($entityManager); 

Then my bootstrap.php

 date_default_timezone_set("America/Detroit"); // Set the default timezone ini_set('display_startup_errors', 1); ini_set('display_errors', 1); error_reporting(- 1); include 'vendor/autoload.php'; include 'doctrine-config.php'; 

And finally, my doctrine-config.php . It is separate for an easy way to call only this file from other parts of your code. In my case, this is called for the CLI and inside the ZF2 singleton when I need a connection to Doctrine.

 // Paths to Entities that we want Doctrine to see $paths = array( "module/Module/src/Entity", "module/MyApplication/src/Entity" ); // Tells Doctrine what mode we want $isDevMode = true; // Doctrine connection configuration $dbParams = array( 'driver' => 'pdo_mysql', 'user' => 'user', 'password' => 'pass', 'dbname' => 'db_name' ); 
+3
source

Source: https://habr.com/ru/post/958648/


All Articles