Yoluk
Yoluk

Reputation: 310

Doctrine 2.3.6 with Slim Framework : where to create doctrine_cli.php

I am currently trying to set up Doctrine with my Slim application.

I read this guide : http://busypeoples.github.io/post/slim-doctrine/. Everything is fine until i hit the Adding the Doctrine Commandline Tool part.

It explains that I need a doctrine_cli.php file in order to set up the command line tool, with this code inside :

<?php

require 'vendor/autoload.php';

$em = //Some code to create EntityManager

$helpers = new Symfony\Component\Console\Helper\HelperSet(array(
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));

Where should I create doctrine_cli.php ?

Thank you.

Upvotes: 1

Views: 1474

Answers (1)

Yoluk
Yoluk

Reputation: 310

I found an answer some minutes ago. It may help someone in the future.

It appears that you can put the config file anywhere, as long as you execute the command line in the same directory.


Explanation :

You call the commandline tool this way (see Doctrine Documentation for reference) :

$ vendor/bin/doctrine orm:schema-tool:create

This calls a bash script in vendor/bin/, wich calls doctrine.php in vendor/doctrine/orm/bin/. In this file you can see this line :

$configFile = getcwd() . DIRECTORY_SEPARATOR . 'cli-config.php';

This means that :

  • The config file used by Doctrine implementation is named cli-config.php, and not doctrine_cli.php.
  • Doctrine search the file with getcwd(), wich refers to the directory you are into when you execute the command line.

In short :

  1. Create a cli-config.php file in any/path/you/want (see Doctrine Documentation for reference).

    <?php
    require 'path/to/vendor/autoload.php';
    $em = //Some code to create EntityManager
    $helpers = new Symfony\Component\Console\Helper\HelperSet(array(
        'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
        'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
    ));
    
  2. Execute your command line tool in the same directory

    $ cd any/path/you/want
    any/path/you/want$ vendor/bin/doctrine orm:schema-tool:create
    

Edit : For Doctrine 2.4, you can also put it in a directory named config and execute the command line tool in config parent directory

Upvotes: 2

Related Questions