Doctrine Entity Manager访问权限

I integrated my Codeigniter with Doctrine ORM the way described in this great tutorial

http://www.joelverhagen.com/blog/2011/05/setting-up-codeigniter-2-with-doctrine-2-the-right-way/.

It says that standard way in CodeIgniter to access a library in a controller is $this->libraryName->libraryMember->someMemberFunction;

It means that i can access Doctrine Entity Manager in Codeigniter Controller this way $this->doctrine->em->someMemberFunction;

The problem is i need to access entity manager in some other place, not just in controller. E.g, i need to use entity manager in some custom model_helper class extending Entity Repository. How can i use it?

$ci = &get_instance();; //get instance of a codeigniter 'core'

$ci->doctrine->em-> ... etc. to use accross the framework

Also, Entity Repository classes extends EntityRepository class in \Doctrine\ORM\EntityRepository.php

This class has protected variable (_em) which is an instance of EntityManager; So eventually your repositoryClass, lets say categories and function that lists categories would look something like this:

class Categories extends EntityRepository {

public function getCategoryList($parent_id = 0) {

 $dql = "SELECT c FROM Entities\Categories c WHERE c.parent_id=:parent_id ORDER BY c.category_name ASC";

    try {
        $query = $this->_em->createQuery($dql);
        $query->setParameter('parent_id', $parent_id);

        return $query->getResult();
    } catch (Exception $e) {

        echo $e->getMessage() . '< br />';
        return;
    }
}

lol, just noticed this was posted ages ago.