I don't find any solution through Symfony's docs and google. I find only stuff about starting an application from scratch.
I have a big own-framework application and i want slowly migrate to Symfony2. I have not the convenience to build a new application from scratch. Until now i cloned the entire symfony folder into my own-framework application's root folder. I was using Doctrine by directly implementing it, whitout touching Symfony, like following.
<?php
namespace QueryBuild\Helpers;
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
class Listing
{
protected $appConfig;
protected $doctrineEntityManager;
public function __construct(\cConfig $app_config)
{
$this->setAppConfig($app_config);
$this->setDoctrineEntityManager();
}
public function setAppConfig($app_config)
{
$this->appConfig = $app_config;
}
public function setDoctrineEntityManager()
{
$paths = array(
$this->getAppConfig()->BasePath() . "/symfony/src/El/Entity/"
);
$isDevMode = true;
// the connection configuration
$dbParams = array(
'driver' => 'sqlsrv', // pdo_sqlsrv for mssql
'host' => $this->getAppConfig()->db->Host,
'user' => $this->getAppConfig()->db->User,
'password' => $this->getAppConfig()->db->Password,
'dbname' => $this->getAppConfig()->db->Database
);
// 5th param on false, to NOT use the simple annotation reader. Otherwise annotations are going to be readed wrong. Can be due to server configurations.
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
$doctrineEntityManager = EntityManager::create($dbParams, $config);
$this->doctrineEntityManager = $doctrineEntityManager;
}
public function getAppConfig()
{
return $this->appConfig;
}
public function getDoctrineEntityManager()
{
return $this->doctrineEntityManager;
}
}
Dont be confused on my namespace, my actual task is to create a query building feature.
Now i don't want anymore to connect to the db by passing the login datas into setDoctrineEntityManager(). I already wrote those informations in /symfony/app/config/parameters.yml . Now my idea was to instanciate symfony to be able to read the configuration, and howewer from symfony to instanciate doctrine.
How can i accomplish this? Many thanks in advice.