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

Asked

Viewed 765 times

6

I’m doing the integration of Doctrine in Codeigniter but I’m having problems configuring the line.

First of all it is important to mention that I followed the guide available on the Doctrine website.

To install the dependencies correctly I used Composer. In this way the structure of the project is organised 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 the Lib "Doctrine" in autoload. So far so good! If boot the application in the browser works well.

The problem is time to configure the Doctrine command line that among many features allows generating the "models" in an automated way from the database.

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

So I was able to verify that 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 navigate through the "windows explorer" or the mac Finder to the vendor/bin folder and open the Doctrine command line file an error arises 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);

Right here I have a question! What do they mean by:

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

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

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

php vendor/bin/Doctrine 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’ve misunderstood what they mean by "replace with file to your Own project bootstrap" in the tutorial.

  • you have set up some environment variable?

  • no, but I don’t think that should be necessary as the php command was installed by Composer and is available. If I do php -help I can see the list of options available

  • Vc is trying to configure on mac or windows?

  • 1

    I am using MAC

2 answers

1

Since Doctrine is not able to recognize and automatically configure the structure and hierarchy of the directories of your application, try to re-install the dependencies of Doctrine within the same folder, example:

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

Getting 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 is kind of boring to implement some libraries in it, so I prefer Frameworks that already follow this standard like Symfony2, Zend Framework 2, Laravel and etc.

0

I just answered a question about how integrate Doctrine with Codeigniter.

I created the file cli-config.php copying some of the index.php and referencing the EntityManager raised in the 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, see how it turned out mine libraries\Doctrine.php.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.