How to configure the doctrine terminal together with a Codeigniter project?

6

I'm doing the Doctrine integration in Codeigniter but I'm having trouble configuring the command line.

First of all it is worth mentioning that I followed the Doctrine page.

In order to install the dependencies correctly, I used Composer. In this way the structure of the project is organized as follows:

/application
--Libraries   <---- Doctrine.php encontra-se aqui
/vendor       <---- aqui encontram-se as libs instaladas para o doctrine
/system
index.php     <---- essas libs são carregadas no root do projecto
...

In the codeigniter settings file I added Lib "Doctrine" to autoload. So far so good! If booting the application in the browser works fine.

The problem is at the time of setting up the doctrine command line, which among many features allows you to generate the models automated from the database.

According to the tutorial, just create a .php file called cli-config.php

As far as I can see, this file should be placed in one of these directories.

array(2) {
  [0]=>
  string(52) "/Applications/MAMP/htdocs/Project/main/app"
  [1]=>
  string(59) "/Applications/MAMP/htdocs/Project/main/app/config"
}

If I browse through the "windows explorer" or mac finder to the vendor / bin folder and open the command line file name doctrine an error appears saying:

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

Soon I have a question! What do they mean by:

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

Assuming that here I should reference the index.php (central file of my codeigniter project) I created a project root file called cli-config.php as it should be done (according to the error message).

All OK. I went to the command line and navigated to the root of my codeigniter project Using composer methods (PHP) I typed.

  

php vendor / bin / doctrine   the output of an error message.

...
<body>
    <div id="container">
        <h1>A Database Error Occurred</h1>
        <p>Unable to connect to your database server using the provided settings.</p><p>Filename: core/Loader.php</p><p>Line Number: 346</p>    </div>
</body>

Can anyone help me? I think I figured wrong what they intended with "replace with file to your own project bootstrap" in the tutorial.

    
asked by anonymous 30.01.2014 / 22:57

2 answers

1

As Doctrine is unable to recognize and automatically configure the structure and hierarchy of your application directories, try re-installing Doctrine dependencies into a single folder, for example:

application/
libraries/
    doctrine/
        {Doctrine Lib}
        composer.json

It has the following structure:

application/
libraries/
    doctrine/
        Doctrine/
            … some libs of Doctrine library
        vendor/
            … some dependencies libraries

Because CodeIgniter does not follow the standards suggested by PHP-FIG, it's kind of annoying to implement some libraries in it, so I prefer Frameworks that already follow this pattern like Symfony2, Zend Framework 2, Laravel, and so on.

    
31.01.2014 / 00:21
0

I recently answered a question about how to integrate Doctrine with CodeIgniter .

I created the file cli-config.php by copying some excerpts from index.php and referencing the EntityManager created in libraries\Doctrine.php .

<?php

use Doctrine\ORM\Tools\Console\ConsoleRunner;

// Constantes do CodeIgniter
define('APPPATH', dirname(__FILE__) . '/application/');
define('BASEPATH', APPPATH . '/../system/');
define('ENVIRONMENT', 'development');

// Inclusão da classe do Doctrine
chdir(APPPATH);
require APPPATH . '/libraries/Doctrine.php';

$doctrine = new Doctrine();
$entityManager = $doctrine->em;

return ConsoleRunner::createHelperSet($entityManager);

For reference, check out my libraries\Doctrine.php .

    
13.05.2015 / 18:20