dflydev / dflydev-doctrine-orm-service-provider

Doctrine ORM Service Provider
MIT License
209 stars 59 forks source link

Could you do an example with mysql connection? #65

Closed danicomas closed 9 years ago

danicomas commented 9 years ago

I have this @simensen @dominikzogg @straccio:

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(

        'dbs.options' => array(
            'db' => array(
                'driver'   => 'pdo_mysql',
                'dbname'   => 'mydbname',
                'host'     => 'iphost',
                'user'     => 'user',
                'password' => 'password',
                'charset'  => 'utf8',
            ),
        )
));

//Is it correct? Or Have I to set up something?
$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
    "orm.em.options" => array(
        "mappings" => array(
        array(
                "type" => "annotation",
                "namespace" => "Entities",
                "path" => __DIR__.'/../Entities',
            )
        ),
     ),
));

//Is it correct? Or Have I to set up something?
$app['orm.ems.default'] = 'mysql';
$app['orm.ems.options'] = array(
   'mysql' => array(
       'connection' => 'mysql',
       'mappings' => array(), 
   ),
);

$article = new Entities\Test();
$article->setContent('Hello world!');
$app['orm.em']->persist($article);
$app['orm.em']->flush();
<?php
namespace Entities;

/**
 * @Entity
 */
class Test {

    /** 
     * @Id @Column(type="integer")
     * @GeneratedValue
     */
    private $id;

    /** @Column(type="text") */
    private $content;

    public function setContent($content)
    {
        $this->content = $content;
    }
}

And it always crash!

danicomas commented 9 years ago

Solved!

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(

        'dbs.options' => array(
            'db' => array(
                'driver'   => 'pdo_mysql',
                'dbname'   => 'mydbname',
                'host'     => 'iphost',
                'user'     => 'user',
                'password' => 'password',
                'charset'  => 'utf8',
            ),
        )
));

$app->register(new Dflydev\Silex\Provider\DoctrineOrm\DoctrineOrmServiceProvider, array(
    "orm.em.options" => array(
        "mappings" => array(
            array(
                "type" => "annotation",
                "namespace" => "Entities",
                "path" => __DIR__.'/../Entities',
            )
        ),
    ),
));

$app['orm.ems.default'] = 'mysql';
$app['orm.ems.options'] = array(
   'mysql' => array(
       'connection' => 'db',
       'mappings' => $app['orm.em.options']['mappings']
   ),
);