Anyone have tried to connect Yii to Doctrine 2.1?
I have used the extension doctrine2orm but it has some problems and the documentations lacks a bit…
Thx
Mojo
Anyone have tried to connect Yii to Doctrine 2.1?
I have used the extension doctrine2orm but it has some problems and the documentations lacks a bit…
Thx
Mojo
It’s not too hard to do the integration yourself. A custom application component can be used for that:
class OrmComponent extends CApplicationComponent
{
public $entityManager;
public function init()
{
// do all Doctrine initialization here as described in its documentation
// ...
$this->entityManager = EntityManager::create($connectionOptions, $config);
}
}
in config/main.php:
'components' => array(
// ...
'orm' => array('class' => 'path.alias.of.OrmComponent'),
),
Now entity manager can be accessed as Yii::app()->orm->entityManager anywhere in your application.
In the next step you can make your component configurable (and hence reusable) by declaring public properties for database connection parameters and other necessary options.
Hi phtamas,
thank you for the answer.
I have copied the doctrine 2.2 directories in framework/vendors/DoctrineORM and i have configured the ‘import’ parameter into main.php like this:
I have modified the ‘components’ voice in main.php like you said:
in the {project name}/components/Doctrine.php i have put my code and inserted the Doctrine Namespaces:
but when i run the app, apache said me:
Can you tell me where i’m wrong?
thank you
Mojo
solved,
I have inserted in main.php the lines
Yii::setPathOfAlias('Doctrine', '{Project path}/framework/vendors/doctrineorm/Doctrine');
Yii::setPathOfAlias('Entities', realpath(dirname(__FILE__) . '/../models'));
and in the import section:
'import'=>array(
'application.models.*',
'application.components.*',
'system.vendors.doctrineorm.doctrine.*',
'system.vendors.doctrineorm.doctrine.ORM.Tools.Setup'
),