Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter - Doctrine ORM Tutorial : A way of enhancing CI
#21

[eluser]jwright[/eluser]
Actually I did get it working using the latest Modular Seperation in this thread
http://ellislab.com/forums/viewthread/12...40/#667656
Now to figure out the best way to use it from other modules.
#22

[eluser]jwright[/eluser]
@lane4 @wiredesignz
After looking into this, it seems there is more to it than I could see initially.
My goal is to combine the power of Modular_Extensions (or Modular Separation) and Doctrine. But I can't see the most appropriate way to do so.
#23

[eluser]Burak Guzel[/eluser]
What part are you having problems with? Getting the plugin to load or getting the models to work?

I have no experience with Matchbox or HMVC, so I'm not sure if I can help.
#24

[eluser]jwright[/eluser]
Just to clarify, I have got Doctrine working within a module using wiredesignz Modular Separation code and I don't think I'd have a problem getting it working with his HMVC code either (since it's from the same codebase according to wiredesignz).

I'm trying to figure out the best application architecture using these two. I'd like to achieve a few features...
- one Doctrine installation powering multiple modules
- ability to use the migrations feature of Doctrine (in/with multiple modules)
- each module can load other modules and there can be module dependencies (meaning modules depending on other modules)
- the above while maintaining the modularity of the modules, meaning that we can still copy a module folder into the modules folder of any HMVC/Doctrine/CI install and it can work with little or no configuration of the module

I know this is all a bit fuzzy and incomplete talking about it without concrete examples. Articulating it in this post has helped me see a little clearer how it might all fit together.

Hopefully I can put something together soon and share it for review and improvement/alternative suggestions.
#25

[eluser]wiredesignz[/eluser]
Try this as a library alternative:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* Doctrine ORM factory for Modular Extensions - PHP5
*
* Install this file as application/libraries/Doctrine_orm.php
*
* @version:     0.2
* $copyright     Copyright (c) Wiredesignz 2009-11-29
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
require_once APPPATH.'vendor/Doctrine/lib/Doctrine.php';

/* this allows Doctrine to load classes as needed */
spl_autoload_register(array('Doctrine', 'autoload'));

class Doctrine_ORM {
    
    public $manager;
    
    function __construct() {
        
        include APPPATH.'/config/database.php';
        
        /* create the DSN connection for Doctrine */
        foreach ($db as $connection => $values) {
            $dsn = "{$db[$connection]['dbdriver']}://{$db[$connection]['username']}:{$db[$connection]['password']}@{$db[$connection]['hostname']}/{$db[$connection]['database']}";
            Doctrine_Manager::connection($dsn, $connection);
        }    
        
        $this->manager = Doctrine_Manager::getInstance();    
    }
    
    static function Factory($model) {
        
        list($path, $_model) = Modules::find($model, NULL, 'models/');
        
        if ($path == FALSE) {
            $path = APPPATH.'models/';
        }
        
        Modules::load_file($_model, $path);
        
        $class = ucfirst($_model);
        return new $class();
    }
}
Version 0.2 : Only started this a short time ago so there may be issues.

application/config/autoload.php
Code:
$autoload['libraries'] = array('doctrine_orm');

Usage:
Code:
$dao = Doctrine_ORM::Factory('module/model');

Note: The Doctrine libraries should be located in a new application/vendor/Doctrine directory.
#26

[eluser]jwright[/eluser]
@wiredesignz this code is interesting. At first I thought the $dao would be like a "Doctrine::" class for just that model folders domain model. But after looking closer actually, I'm not sure how to use $dao...

Also, I've started a new topic about this CodeIgniter + Doctrine + HMVC
#27

[eluser]Unknown[/eluser]
To make the process easier of using Doctrine with CodeIgnitier, we've developed the Doctrine CodeIgniter LIbrary.

Enjoy!
#28

[eluser]albertleao[/eluser]
I've been using PHPActiveRecord. How does Doctrine compare with that?




Theme © iAndrew 2016 - Forum software by © MyBB