CodeIgniter 2/Doctrine 2 Installation

If you want a quick way of getting Doctrine 2 working with CodeIgniter 2, you can download a pre-configured installation from my GitHub repository. There are currently three branches available:

  • master – the latest stable versions of CodeIgniter and Doctrine.
  • develop – the latest development versions of CodeIgniter and Doctrine. Not recommended for production use.
  • doctrine-2.1 - the latest stable version of CodeIgniter, and the latest stable 2.1.X version of Doctrine. This branch is provided as a way of keeping Doctrine 2.1 applications up to date without breaking backwards compatibility.

For more information, read my post on integrating Doctrine 2 with CodeIgniter 2

  • http://gravatar.com/tiyowan Hamza Bhatti

    Hey there, great work on the package. However, MySQL server complains when you try to create the schema using the CLI tool for the example models (i.e. User and Group) that are used in the master branch of your repo.

    I spent some time debugging the issue, and as it turns out, MySQL complains about your models because ‘group’ is a reserved keyword. (See http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html)

  • Steve

    Hi Joseph,

    I’m having trouble getting custom repositories to work, and was hoping you could give me some advice.

    - I have an entity ‘Foo’ in application/models/Entity/Foo.php
    - Foo.php’s @Entity() annotation includes the parameter repositoryClass = “FooRepository”
    - When I run “orm:generate-repositories models”, FooRepository.php is created within applications/models/Entity

    The problem arises when I add a custom method to my new repo, and try accessing it. PHP complains that the method doesn’t exist. My code looks like this:

    $this->load->library(‘doctrine’);
    $repo = $this->doctrine->em->getRepository(‘Entity\Foo’);
    $repo->bar(); // This is where it breaks

    If I debug the repo on its own, I can see that Doctrine 2 is in fact returning it, but it seems to be the default one provided by Doctrine 2, and it lacks my custom methods.

    Any idea on what the problem could be, or how to solve it?

    Thanks

    • http://wildlyinaccurate.com/ Joseph

      Hi Steve,

      If I understand correctly, the repository that Doctrine returns is in fact your custom FooRepository? I.e. var_dump($this->doctrine->em->getRepository(‘Entity\Foo’) instanceof Entity\FooRepository); // bool(true)

      If this is the case, I would clear all of your caches (Memcache, APC, etc) and try again.

      It’s difficult to help without seeing all of your code. If you’re still having trouble, send me a link to a Pastebin, Gist, or similar.

    • http://wildlyinaccurate.com/ Joseph

      Sorry Steve, I’ve just re-read your comment and realised that Doctrine isn’t returning your FooRepository.

      Your @Entity annotation should have the full class name (including namespaces) like this: @Entity(repositoryClass="Entity\FooRepository")

      If you need an example, I’ve got some working code you can look at here: Entity\Entry and Entity\EntryRepository

  • Igor

    Hi!
    I just downloaded latest version of CodeIgniter+Doctrine and put it in my ‘www’ folder (I use wamp)
    When I try to access it – it shows me “Internal Server Error” (I didn’t make any changes).
    At the same time latest CodeIgniter, downloaded from it’s site (and being in neighbour folder) works fine.
    Should ‘CodeIgniter+Doctrine’ work or I should make some changes?

    • Igor

      Sorry,
      fixed myself, rewrite_module on apache was switched off.

  • hthyngoc

    Integrating Doctrine 2 with CodeIgniter 2 is good. I tried to build a small application such as:
    - create form
    - validate form (not use validate form of CI, use validate of doctrine. Ex: unique, …)
    - save form to database (if not validate show error)
    But i can not do it. Please show me how i can do it.
    PS: How in model i can call EntityManager $em (for check exits value, unique, …)

  • Axel

    Cool man! you save my life with this!!! :D did you think about add mongo Doctrine ODM support ?? could be amazing if you add this.

  • Pablo Bozzolo

    GREATTTTTTTT! My congratulations!

  • http://www.ligams.com Stéphane

    Exaclty what i did not need to do by myself, many thanks for this package and explanations. CodeIgniter is a pretty nice framework, but no built-in ORM is quiet boring…

  • Pingback: Integrating Doctrine 2 with CodeIgniter 2 « Wildly Inaccurate

  • Pingback: Doctrine 2.1 Released