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.

Drop-in PHP Doctrine plugin

December 03, 2008 1:09pm

Subscribe [13]
  • #16 / May 03, 2009 6:38am

    andriansandi

    5 posts

    Is the CLI working with this plugin?

  • #17 / May 03, 2009 8:34am

    sshz

    24 posts

    Is the CLI working with this plugin?

    There is no CLI in plugin, I use this for CLI, works great with this plugin, there is two files, put them in application folder

    doctrine.php

    <?php
    
    require_once('config/database.php');
    require_once('../system/plugins/doctrine_pi.php');
    // Configure Doctrine Cli
    // Normally these are arguments to the cli tasks but if they are set here the arguments will be auto-filled
    $config = array('fixtures_path'  =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/fixtures',
                    'data_fixtures_path'  =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/fixtures',
                    'models_path'         =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/models',
                    'migrations_path'     =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/migrations',
                    'sql_path'            =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/sql',
                    'yaml_schema_path'    =>  dirname(__FILE__) . DIRECTORY_SEPARATOR . 'doctrine/schema');
    
    
    $cli = new Doctrine_Cli($config);
    $cli->run($_SERVER['argv']);
    
    ?>

     

    dt

    #!/usr/local/bin/php
    <?php
    define('BASEPATH','.'); // mockup that this app was executed from ci :wink:
    chdir(dirname(__FILE__));
    include('doctrine.php');
    
    ?>

    run the dt file

  • #18 / May 16, 2009 5:55am

    fourcs

    10 posts

    Using CI_1.7.1 and doctrine-1.1.1. Executing dt produces PHP warning that it can’t find doctrine_pi.php and PHP fatal error for not finding the file, yet the file is where it should be, namely, in the system/plugins folder.

  • #19 / Sep 21, 2009 11:01am

    iDVB

    56 posts

    CI-Doctrine - built for Doctrine 1.0 (included in package)

    A colleague of mine recently turned me on to Doctrine, an Object-Relational Mapper for PHP5. There are plenty of great resources that explain exactly what using an ORM gets you, but for me it boils down to being able to transparently serialize objects into my database in a human-understandable way.

    The problem is that Doctrine didn’t really have CodeIgniter in mind when it was developed, so it can be a little difficult and confusing to install it in such a way as to be maintainable and comfortable to use for a CI developer. I read the Wiki article, which is a little dated (for version 0.1 rather that version 1.0), and requires hacking of core CodeIgniter files. I also found a helpful blog entry, which migrates any core hacking out into a hook, but it still required some configuration and couldn’t be selectively disabled on some pages (not every page needs that kind of page overhead). I want drop-in-and-go ease, and flexibility.

    So, I developed my own solution in the form of a CI plugin. It grabs information from the database.php configuration file, just like the hook, but is as simple as dropping it into your CI plugins directory and writing your schema file.

    The Readme file follows:

    I read later in this thread that others have gotten this plugin working even with other versions of doctrine? Is this supposed to work that way? is upgrading this plugin as simple as dropping in the new doctrine code?

  • #20 / Sep 21, 2009 11:08am

    Nick Husher

    364 posts

    Suggestion: Give it a try and let me know how it works. 😉

    Doctrine and CodeIgniter are very loosely coupled in my plugin: it’s basically just adding your Doctrine classes to the global namespace (if you load the Doctrine plugin somewhere in your request) and letting you do what you want. It should continue to work as long as the API to turn a schema into a set of class files and fixtures into database data haven’t changed. I’m not an expert in Doctrine, but I don’t see why 1.1 wouldn’t work with the plugin. I don’t know anything about Doctrine 2.0, so I can’t speak to that.

  • #21 / Sep 21, 2009 11:23am

    iDVB

    56 posts

    Suggestion: Give it a try and let me know how it works. 😉

    Doctrine and CodeIgniter are very loosely coupled in my plugin: it’s basically just adding your Doctrine classes to the global namespace (if you load the Doctrine plugin somewhere in your request) and letting you do what you want. It should continue to work as long as the API to turn a schema into a set of class files and fixtures into database data haven’t changed. I’m not an expert in Doctrine, but I don’t see why 1.1 wouldn’t work with the plugin. I don’t know anything about Doctrine 2.0, so I can’t speak to that.

    Thanks for the quick reply Nick. Can you maybe look at my other thread. I am thinking of switching to your plugin implementation if it will help fix my issue. Basically, I just interested in you to chime in on if you think you plugin will in-advertantly help me here…

    http://ellislab.com/forums/viewthread/129635/

  • #22 / Sep 21, 2009 11:38am

    Nick Husher

    364 posts

    No, it probably won’t solve your problem. CI probably still won’t be accessible within your Doctrine objects (although I don’t know for sure, never tried it!). The way I’ve been using my plugin keeps all the hardcode Doctrine stuff at arms length by keeping it within the CI model files. I don’t work directly on the generated Doctrine class files because I’m changing my schema enough that I want the flexibility to nuke all my models and rebuild them from yaml at will. Anything that needs CI to operate goes in a CI model, while my interface with the database is all Doctrine-powered. I don’t know if that makes any sense to you at all

  • #23 / Sep 21, 2009 11:49am

    iDVB

    56 posts

    I think I understand. However, I guess I’m still confused as to how most people use CI and Doctrine then.
    Does it not make sense to be able to have a “User” object/Doctrine Class that has the ability to say…
    User.login(password) and have that user now logged in.

    In order to do that I’d need the CI Session class accessable from within that User Doctrine object/class.

    I’m really just trying to wrap my head around how Doctrine is supposed to play with CI.

    D

  • #24 / Sep 24, 2009 11:45am

    iDVB

    56 posts

    I’m currently having two issues with this Doctrine plugin most likely due to me not understanding how to use it fully.

    1) My “Doctrine_Manager::getInstance()->setAttribute()“s don’t seem to work when I place them in the “doctrine_pi.php” file. Is this not where I should stick the code to get those working? Here is my code:

    <?php
    
    require_once 'doctrine'.DIRECTORY_SEPARATOR.'Doctrine.php';
     
    @include APPPATH . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'database' . EXT;
    
    define('DOCTRINE_DIRECTORY', APPPATH . DIRECTORY_SEPARATOR . 'doctrine' . DIRECTORY_SEPARATOR);
    define('MODELS_DIRECTORY', DOCTRINE_DIRECTORY . 'models' . DIRECTORY_SEPARATOR);
    define('FIXTURES_DIRECTORY', DOCTRINE_DIRECTORY . 'fixtures' . DIRECTORY_SEPARATOR);
    define('SCHEMA_DIRECTORY', DOCTRINE_DIRECTORY . 'schema' . DIRECTORY_SEPARATOR);
    
    
    // Set the autoloader
    spl_autoload_register(array('Doctrine', 'autoload'));
    
    //optional, you can set this to whatever you want, or not set it at all
    //Doctrine_Manager::getInstance()->setAttribute('model_loading', 'aggressive');
    
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, TRUE);
    Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, TRUE);
    
    // Load the Doctrine connection
    // (Notice the use of $active_group here, to make it easy to swap out
    //  you connection based on you database.php configs)

    ...the rest is standard->

    2) Whenever I use “doctrine_destroy_database” I get a bunch of PHP errors regarding relations in the DB that are preventing certain tables form being dropped before others. When I go into phpMyAdmin I get those same errors but if I just change the order in which I manually drop them it then works.


    Any ideas what I’m doing wrong?

  • #25 / Oct 10, 2009 5:58am

    shinokada

    144 posts

    CI-Doctrine - built for Doctrine 1.0 (included in package) link is broken.
    Is there any new link available?

  • #26 / Oct 29, 2009 7:27pm

    iDVB

    56 posts

    In regards to the “doctrine_uninstall()” function:
    I’m never able to execute this without receiving the error below. I consistently have to delete the DB and Models manually.
    I understand this is due to foreign key constraints. However, don’t most projects have these FKs, thus would that not mean that in most cases people would never be able to successfully use the “doctrine_uninstall()” or “doctrine_reinstall()” functions?

    Maybe I’m doing something wrong? Can someone give me a bit of details here?

    Fatal error: Uncaught exception 'Doctrine_Connection_Mysql_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1217 Cannot delete or update a parent row: a foreign key constraint fails' in /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine/Doctrine/Connection.php:1075 Stack trace: #0 /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine/Doctrine/Connection.php(1023): Doctrine_Connection->rethrowException(Object(PDOException), Object(Doctrine_Connection_Mysql)) #1 /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine/Doctrine/Export.php(95): Doctrine_Connection->execute('DROP TABLE grou…') #2 /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine_pi.php(83): Doctrine_Export->dropTable('group_table') #3 /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine_pi.php(57): doctrine_destroy_database() #4 /Projects/RB Projects/projects/gpsapp/www/system/application/controllers/docsetup.php(8): doctrine_uninstall() #5 /Projects/RB Projects/project in /Projects/RB Projects/projects/gpsapp/www/system/plugins/doctrine/Doctrine/Connection.php on line 1075
  • #27 / Oct 30, 2009 10:53am

    iDVB

    56 posts

    Bump

  • #28 / Nov 03, 2009 12:34pm

    iDVB

    56 posts

    Bump

    No one can shed any light?

  • #29 / Nov 30, 2009 6:25am

    MarcelMarnix

    3 posts

    Bump

    No one can shed any light?

    I got my ci and doctrine work with this tutor.

    Hope you can get something out of it
    http://www.phpandstuff.com/articles/codeigniter-doctrine-from-scratch-day-1-install-and-setup

  • #30 / Jun 20, 2010 2:43am

    Beano

    3 posts

    For anyone who is interested - I’ve posted up a project starter on my blog - a dev ready incorporation of the following technologies:

    - ExtJS : client side JS library,
    - CodeIgniter : presentation + domain tier,
    - Doctrine : ORM data layer framework

    Some features of this project starter are:
    - CodeIgniter Models have been replaced with Doctrine Records
    - Doctrine is loaded into CI as a plugin
    - RoR type before and after filters….
    - Doctrine transactions automatically wrapped around every action at execution time (ATOMIC db updates)

    Basic Role based security (I think Redux may be in there as well?)
    Simply extract, hook up the database.php config file and viola…. You can start coding your layouts, views and models. Probably a few things to iron out - but enjoy!

    Hope it helps

    GET IT AT: thecodeabode.blogspot.com

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

ExpressionEngine News!

#eecms, #events, #releases