DEV Community

Adamo Crespi for Serendipity HQ

Posted on • Originally published at io.serendipityhq.com on

How to use the Doctrine command line developing a Symfony Bundle

Maybe you need to use the Doctrine’s command line while you are developing a Symfony Bundle (or anything else).

This will make you able, for example, to validate the schema or to convert an annotated schema to its XML counterpart.

Here is how to use Doctrine command line outside of a Symfony Application.

You have to simply create a cli-config.php file and put it into the root directory of your developing bundle.

<?php 

use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;

$paths = [getcwd() . "/Model"];
$isDevMode = true;

// the connection configuration
$dbParams = array( 'driver' => 'pdo_mysql',
    'user' => 'root',
    'password' => 'root',
    'dbname' => 'test_your_bundle',
);

// @see http://stackoverflow.com/a/19129147/1399706
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);

$entityManager = EntityManager::create($dbParams, $config);

return ConsoleRunner::createHelperSet($entityManager);
Enter fullscreen mode Exit fullscreen mode

Now you can use vendor/bin/doctrine your:command to perform the task you need.

Very simple! 🙂

Remember to “Make. Ideas. Happen.”.

I wish you flocking users, see you soon!

L'articolo How to use the Doctrine command line developing a Symfony Bundle proviene da ÐΞV Experiences by Serendipity HQ.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay