ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

CodeIgniter 2 and Doctrine 2

July 04, 2010 5:39pm

Subscribe [13]
  • #1 / Jul 04, 2010 5:39pm

    Rui Lima

    10 posts

    Any good way to do this with a non-intrusive approach?

    I’m not able to find any tutorial with the version 2 of both api.

  • #2 / Jul 06, 2010 6:55pm

    Rui Lima

    10 posts

    I’ve found this:
    http://www.doctrine-project.org/projects/orm/2.0/docs/cookbook/integrating-with-codeigniter/en#integrating-with-codeigniter

    but got lost on:
    “Put the Doctrine folder (the one that contains Common, DBAL, and ORM) inside that same
    libraries folder.”

    there is no folder that contains Common, DBAL and ORM :(

  • #3 / Jul 07, 2010 7:10pm

    Rui Lima

    10 posts

    I’m almost there… :D

  • #4 / Jul 08, 2010 8:59am

    JiPi

    4 posts

    Is CI2 usable yet ? What stage of development is it currently ? We hadn’t any news (on frontpage I mean) since the march…

  • #5 / Jul 08, 2010 12:38pm

    Rui Lima

    10 posts

    Yes!
    see here: http://ellislab.com/forums/viewreply/770721/

    By the way, i think i’ve got it working CI2 + Doctrine 2, using a library as approach.
    Even have the CLI working.
    I’ll post here HOW TO when i’ve some time. maybe in weekend.

  • #6 / Jul 19, 2010 4:59pm

    Deyan Yankov

    4 posts

    Yes!
    see here: http://ellislab.com/forums/viewreply/770721/

    By the way, i think i’ve got it working CI2 + Doctrine 2, using a library as approach.
    Even have the CLI working.
    I’ll post here HOW TO when i’ve some time. maybe in weekend.

    Hello! Could you please post your Doctrine.php (the library configuration) file? I am banging my head ofr 3 days already to get Doctrine 2 working and nothing but headache (maybe also because of the death metal i’m listening too 😊) ) Thank you very very much! There’s no other info on the net ... :(

  • #7 / Jul 20, 2010 10:59am

    Rui Lima

    10 posts

    Hello, sorry! i’ve been a little sick this days.
    I will post the how to ASAP.

  • #8 / Jul 28, 2010 8:02am

    Rui Lima

    10 posts

    first of all, sorry not being able to post this sooner.
    How to integrate CodeIgniter 2 and Doctrine 2
    Here is my final folder structure:
    please see attachement 1.png

    You should take careful look at libraries and models.
    Inside libraries I have a Library called Doctrine.php and have 2 folders one to CLI and other to “Web”.
    Then inside models I have a folder called Entities. I want to have my own models, but this one will not access directly to DB, for them the DB are the Entities.

    In codeigniter what sould be done?!

    $autoload['libraries'] = array('doctrine');

    then confirm that inside DoctrineCLI\cli-config.php the database connection is the same as the codeigniter database.php.
    and that’s all.
    i attach my files.
    i’m using xampp for windows, so hope you don’t have any problems.
    i’m not a expert, but any problem/observation post it here.

    please get my forlder structure at:
    http://1e4411af.realfiles.net
    you will need 7ZIP

  • #9 / Sep 04, 2010 5:09pm

    subbu.genie

    3 posts

    Hey,

    First of all thanks a lot for the post. I tried something similar except that I dont have a CLI. The other thing to be noted is that Doctrine2 depends and works a lot on Namespaces which have come in PHP5.3. So while creating a model or referencing the same quoting them against their namespaces is very much required for Doctrine2. I would soon post a zip file of something I have done.

    Subbu

  • #10 / Sep 13, 2010 7:24am

    Prophet

    38 posts

    Hi everyone. I’ve been trying to implement D2 with CI2 for the last few days. I’m still wrapping my head around the Doctrine ClassLoaders and PHP namespaces but I think I understand them well enough now.

    Here’s a bit of what I’ve learned, just in case it helps somebody else.

    If you followed the Doctrine documentation when you set up your bootstrap file (application/libraries/Doctrine.php), you may have noticed the line:

    $entitiesClassLoader = new ClassLoader('models', rtrim(APPPATH, '/' ));

    This tells Doctrine’s ClassLoader to look in application/ (or so I thought) whenever you request a class from the models namespace. The thing that took me a while to work out is that it actually looks in application/models.

    So if you would like to create a User class, you need to create application/models/User.php and have it look something like this:

    namespace models;
    
    class User
    {
        private $id;
        private $username;
        private $password;
    }

    You can then do something like $user = new models\User;

    I hope this helps somebody, because it took me a while to work out how to load classes like this. This way seems a bit more complicated then Doctrine 1.2 so maybe I’m not doing it properly? If that’s the case, could somebody point me in the right direction 😊

  • #11 / Oct 13, 2010 1:16pm

    hooflung64

    11 posts

    Now to just have it work with Modular Separation or the new all in one package.

  • #12 / Oct 28, 2010 1:27am

    kkruecke

    6 posts

    I tried something similar except that I dont have a CLI.

    Assuming you installed Doctrine using pear

    $ sudo pear install pear.doctrine-project.org/doctrineORM
    $ pear list -c pear.doctrine-project.org
    Installed packages, channel pear.doctrine-project.org:
    ======================================================
    Package        Version    State
    DoctrineCommon 2.0.0RC1   beta
    DoctrineDBAL   2.0.0BETA4 beta
    DoctrineORM    2.0.0BETA4 beta

    and (on Ubuntu, for example) these packages are now located in /usr/share/php/Doctrine

    $ ls -1 /usr/share/php/Doctrine
    Common
    DBAL
    ORM
    Symfony

    and the doctrine command line utility is installed into /usr/bin. With this setup, then this is a version of cli-config.php you can use. cli-config.php goes in your project’s folder. Don’t place it in /usr/bin. Change the database connection settings, of course, to your settings.

    <?php
    require_once 'Doctrine/Common/ClassLoader.php';
    
    $classLoader = new \Doctrine\Common\ClassLoader('Entities', __DIR__);
    $classLoader->register();
    $classLoader = new \Doctrine\Common\ClassLoader('Proxies', __DIR__);
    $classLoader->register();
    
    $config = new \Doctrine\ORM\Configuration();
    $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
    $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
    $config->setMetadataDriverImpl($driverImpl);
    
    $config->setProxyDir(__DIR__ . '/Proxies');
    $config->setProxyNamespace('Proxies');
    
    $connectionOptions = array(     'driver' => 'pdo_mysql',
        'dbname' => 'bugs',
         'user' => 'bugs',
        'password' => 'sY7Rsk47',
        ''host' => 'localhost' );
    
    $em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
    
    $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
        'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
        'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
    ));

    There instructions are also at http://wp.me/pj3WD-vn.

  • #13 / Nov 01, 2010 3:41pm

    kkruecke

    6 posts

    cli-config.php of course goes in your project directory not in /usr/bin. I didn’t make that proint clear.

  • #14 / Nov 11, 2010 4:00pm

    kkruecke

    6 posts

    A standalone php program of Doctrine 2 Cookbook example (at least the first portion) is described here

  • #15 / Jan 04, 2011 10:00am

    g_montel

    9 posts

    So if you would like to create a User class, you need to create application/models/User.php and have it look something like this:

    namespace models;
    
    class User
    {
        private $id;
        private $username;
        private $password;
    }

    You can then do something like $user = new models\User;

    I hope this helps somebody, because it took me a while to work out how to load classes like this.

    THANKS A LOT!
    It definitely helped 😊

    Geoffroy

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases