Yii Framework Forum: Doctrine 2 ORM - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Doctrine 2 ORM Rate Topic: ***** 1 Votes

#1 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 13 May 2011 - 12:26 PM

Hi Everyone,

Just a heads up that I've released my first implementation of Doctrine 2 ORM and Yii.

Feedback is appreciated.

Get the extension here
0

#2 User is offline   AndrewK 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 12-May 10

Posted 20 May 2011 - 06:21 AM

View Post_wk_, on 13 May 2011 - 12:26 PM, said:

Just a heads up that I've released my first implementation of Doctrine 2 ORM and Yii.

Feedback is appreciated.


Looks good. I had implemented my own Doctrine 2 extension, but yours looks more complete so I will switch to using it instead.

In terms of implementation, the only suggestion I have is using

\Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands($cli);


to add all the console commands rather than adding them individually.

Also, in your sample configuration you set a value for 'entityPath' that is never used (there is no corresponding setter method in the Configuration class). I am guessing that this was the precursor to 'mappingPaths' which is where this value should go.
0

#3 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 24 May 2011 - 08:06 AM

Thanks for your comments, I'll take a look at the sample config. It may be that I had a change of mind during initial development of option names.
0

#4 User is offline   Khánh Trần 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-February 11

Posted 17 August 2011 - 09:51 PM

Thanks _wk_.

I'm in first stage of choosing a ORM layer for our new project. I choose MongoDB and Yii. But as author of YiiMongoDBSuite said that his extensions is not best for MongoDB, so we are estimating Doctrine2. I'm new to Doctrine (but I've experienced with Java's Hibernate) so I would like to ask that could we use the transparent feature of Doctrine MongoDB extensions with your extension?

@yii guys :), I hear that the next Yii 2.0 version will have the same feature as Doctrine does that transparent to DB layer no matter MySQL or NoSQL or MongoDB :). Could I wait to that?

Regards,
Khanh Tran
0

#5 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 22 August 2011 - 03:41 AM

Hi there,

This plugin was written for the for the ORM project only and won't work with the MongoDB ODM library but it may be something I'll consider adding if there is enough interest in its implementation.

_wk_
0

#6 User is offline   khanhtran 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 23-May 09

Posted 22 August 2011 - 11:34 PM

View Post_wk_, on 22 August 2011 - 03:41 AM, said:

Hi there,

This plugin was written for the for the ORM project only and won't work with the MongoDB ODM library but it may be something I'll consider adding if there is enough interest in its implementation.

_wk_


Dear all,

I just changed some code to add ODM to Wildkat extension. Thanks _wk_ for a nice extensions, it help me to understand about Yii classloader and PHP 5.3 classloader :)

** Note that: you should get new YamlDriver from Symfony, I could not make Annotation work, but I think YAML is good because we can change ODM <-> ORM versa.

Here is the code:
public function getMongo() {
   		/**
        * MongoDB handler...
        */
        $configD = new MongoDBConfiguration();
        $configD->setProxyDir('/tmp/doctrine-mongo');
        $configD->setProxyNamespace('Proxies');
 
        $configD->setHydratorDir('/tmp/doctrine-mongo/cache');
		$configD->setHydratorNamespace('Hydrators');
        
		$options = array();
        $options['mappingPaths'] = 'ext.Wildkat.YiiExt.DoctrineOrm.mapping.mongo';
        $options['mappingDriver'] = 'YamlDriver';
        $driver = $this->_getMongoMappingDriver($options);
        $configD->setMetadataDriverImpl($driver);
 
        try { 
        	$this->dm = DocumentManager::create(new MongoConnection("mongodb://localhost"), $configD);
        } catch (Exception $e) { 
        	var_dump($e->getMessage()); 
        }
        return $this->dm;
    }

/**
     * Take the configuration and return a mapping driver
     *
     * @param array &$config the driver options
     *
     * @return Doctrine\ORM\Mapping\Driver\Driver
     */
    private function _getMongoMappingDriver(array & $config)
    {
        $drivers = array(
            'XmlDriver'  => 'Doctrine\ORM\Mapping\Driver\XmlDriver',
            'YamlDriver' => 'Doctrine\ODM\MongoDB\Mapping\Driver\YamlDriver',
        );

        if (is_array($config['mappingPaths']) === true) {
            foreach ($config['mappingPaths'] as $index => $path) {
                $config['mappingPaths'][$index] = \Yii::getPathOfAlias($path);
            }
        } else {
            $config['mappingPaths'] = \Yii::getPathOfAlias($config['mappingPaths']);
        }

        // set default annotation driver
        if (array_key_exists($config['mappingDriver'], $drivers) === false
            || $config['mappingDriver'] === 'AnnotationDriver'
        ) {
            $reader = new AnnotationReader();
            $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
            $driver = new AnnotationDriver($reader, $config['mappingPaths']);
            unset($config['mappingDriver']);
            unset($config['mappingPaths']);
            return $driver;
        }

        $mappingClass = $drivers[$config['mappingDriver']];
        $driver       = new $mappingClass($config['mappingPaths']);

        if (isset($config['mappingDriverOptions']) === true) {
            foreach ($config['mappingDriverOptions'] as $key => $value) {
                $method = 'set' . ucfirst($key);
                if (method_exists($driver, $method) === true) {
                    $driver->{$method}($value);
                }
            }

            unset($config['mappingDriverOptions']);
        }

        unset($config['mappingDriver']);
        unset($config['mappingDriverPaths']);

        return $driver;

    }//end _getMappingDriver()

0

#7 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 23 August 2011 - 04:23 AM

Hi khanhtran,

Thanks for taking the time to look at improvements to my initial extensions. I'll take a look at your code to see if it can be incorporated. At first glance though, I would make changes in how it pull ODM configuration to allow for multiple configurations like the ORM does.

_wk_
0

#8 User is offline   yyeshua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 15-October 11
  • Location:Honduras

Posted 18 October 2011 - 01:46 PM

Hi hi...

How its going the project?? I do not see any change from May 13...
I think this it's a great extension, but Im so losing in the code :P

Anyway, where I must put my Entities Classes?
I must include some code before declare the Entitie Class?

/**
* Something here?????????
*/
class MyEntity{

}


Thanks
0

#9 User is offline   _wk_ 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 152
  • Joined: 22-January 10

Posted 18 October 2011 - 02:13 PM

@yyeshua

Your entity classes need to be somewhere on your current include path. You can also put them inside your models directory, see the example here: http://code.google.c...entity/User.php
0

#10 User is offline   yyeshua 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 18
  • Joined: 15-October 11
  • Location:Honduras

Posted 19 October 2011 - 12:07 PM

Oh man, many thanks :)

Hey... I was trying but I have some problem. I follow the config files, i was download the Doctrine ORM, i was move the Command... well, the case is when I execiute:

php yiic doctrineorm orm:schema-tool create


I get "No Metadata classes to process".

Some idea??
0

#11 User is offline   marc d 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 20-December 11

Posted 20 December 2011 - 03:43 PM

When I execute: php yiic.php doctrineorm orm:schema-tool:create

I get this error:
[Doctrine\ORM\Mapping\MappingException]
File mapping drivers must have a valid directory path, however the given path [/opt/project/protected/extensions/Wildkat/YiiExt/DoctrineOrm/mapping] seems to be incorrect!

I've take a look at the path and the mapping directory doesn't exists.
If I create it I get the message: "No Metadata classes to process."

The mapping path came from the config file:
'entityManager' => array(
'default' => array(
'connection' => 'default',
'metadataCache' => 'default',
'queryCache' => 'default',
'entityPath' => 'application.models.entity',
'mappingDriver' => 'AnnotationDriver',
'mappingPaths' => array(
'ext.Wildkat.YiiExt.DoctrineOrm.mapping'
),
'proxyDir' => 'application.data',
'proxyNamespace' => 'Proxy',
),
),

I didn't find any documentation about the config so I don't know what to do with the mappingPaths. should it be the path where I've create my Annotation classes? I've try without any luck.

Can someone help me about this, or can provide me a config documentation?

thanks
0

#12 User is offline   marc d 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 20-December 11

Posted 21 December 2011 - 08:56 AM

View Postmarc d, on 20 December 2011 - 03:43 PM, said:

When I execute: php yiic.php doctrineorm orm:schema-tool:create

I get this error:
[Doctrine\ORM\Mapping\MappingException]
File mapping drivers must have a valid directory path, however the given path [/opt/project/protected/extensions/Wildkat/YiiExt/DoctrineOrm/mapping] seems to be incorrect!

I've take a look at the path and the mapping directory doesn't exists.
If I create it I get the message: "No Metadata classes to process."

The mapping path came from the config file:
'entityManager' => array(
'default' => array(
'connection' => 'default',
'metadataCache' => 'default',
'queryCache' => 'default',
'entityPath' => 'application.models.entity',
'mappingDriver' => 'AnnotationDriver',
'mappingPaths' => array(
'ext.Wildkat.YiiExt.DoctrineOrm.mapping'
),
'proxyDir' => 'application.data',
'proxyNamespace' => 'Proxy',
),
),

I didn't find any documentation about the config so I don't know what to do with the mappingPaths. should it be the path where I've create my Annotation classes? I've try without any luck.

Can someone help me about this, or can provide me a config documentation?

thanks


For those who get the same issue, I've find that it's the mappingPaths. I've change the mappingPaths to the path where my entities annotation classes are:

'entityManager' => array(
'default' => array(
'connection' => 'default',
'metadataCache' => 'default',
'queryCache' => 'default',
'entityPath' => 'application.models.Entity',
'mappingDriver' => 'AnnotationDriver',
'mappingPaths' => array(
'application.models.Entities'
),
'proxyDir' => 'application.data',
'proxyNamespace' => 'Proxy',
),
),

now the command line: php yiic doctrineorm orm:schema-tool:create --dump-sql gor futher but get a problem loading the classes:
ATTENTION: This operation should not be executed in an production enviroment.

Creating database schema...
PHP Error[2]: include(test.php): failed to open stream: No such file or directory
in file /opt/fw/yii-1.1.8/framework/YiiBase.php at line 421
#0 /opt/fw/yii-1.1.8/framework/YiiBase.php(421): autoload()
#1 unknown(0): autoload()
#2 unknown(0): spl_autoload_call()
....
0

#13 User is offline   marc d 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 20-December 11

Posted 21 December 2011 - 12:45 PM

View Postmarc d, on 21 December 2011 - 08:56 AM, said:

For those who get the same issue, I've find that it's the mappingPaths. I've change the mappingPaths to the path where my entities annotation classes are:

'entityManager' => array(
'default' => array(
'connection' => 'default',
'metadataCache' => 'default',
'queryCache' => 'default',
'entityPath' => 'application.models.Entity',
'mappingDriver' => 'AnnotationDriver',
'mappingPaths' => array(
'application.models.Entities'
),
'proxyDir' => 'application.data',
'proxyNamespace' => 'Proxy',
),
),

now the command line: php yiic doctrineorm orm:schema-tool:create --dump-sql gor futher but get a problem loading the classes:
ATTENTION: This operation should not be executed in an production enviroment.

Creating database schema...
PHP Error[2]: include(test.php): failed to open stream: No such file or directory
in file /opt/fw/yii-1.1.8/framework/YiiBase.php at line 421
#0 /opt/fw/yii-1.1.8/framework/YiiBase.php(421): autoload()
#1 unknown(0): autoload()
#2 unknown(0): spl_autoload_call()
....



To fix the class loading issue, do not use namespace into the annotation classes cause the yii autoloader doesn't work using them and will not find the libraries.

I will also mention that the vendor/Symfony directory need to get a copy of the Doctrine/Symfony/Component directory.

hope it help someone.
0

#14 User is offline   ibo_s 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-July 11

Posted 11 October 2012 - 10:41 AM

Can't get it working with annotations. How to configure ?

DoctrineContainer line 391:
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');

Fatal error: Call to undefined method Doctrine\Common\Annotations\AnnotationReader::setDefaultAnnotationNamespace() in [...]\DoctrineContainer.php on line 391
0

#15 User is offline   ibo_s 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 19-July 11

Posted 11 October 2012 - 10:44 AM

View Postibo_s, on 11 October 2012 - 10:41 AM, said:

Can't get it working with annotations. How to configure ?

DoctrineContainer line 391:
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');

Fatal error: Call to undefined method Doctrine\Common\Annotations\AnnotationReader::setDefaultAnnotationNamespace() in [...]\DoctrineContainer.php on line 391


Without that line I get this:
Doctrine\Common\Annotations\AnnotationException

[Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class Bla does not exist, or could not be auto-loaded.
0

#16 User is offline   bijosh 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 10-May 13

Posted 29 May 2013 - 11:36 PM

View Postibo_s, on 11 October 2012 - 10:44 AM, said:

Without that line I get this:
Doctrine\Common\Annotations\AnnotationException

[Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class Bla does not exist, or could not be auto-loaded.


Hi, did you get any solution for this issue?? I'm also facing the same problem.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users