WebTigers: Working with Doctrine ORM, Part 1 |
[eluser]webtigers[/eluser]
Having just begun working with Doctrine within CI, I thought I'd post some of my code and limited experience to date. Doctrine, in a word, ROCKS!, but like any other piece of complex software, this ORM has its idiosyncrasies. Hopefully, my experiences will help you avoid some of the gotchas I ran into. INSTALLING DOCTRINE AS A CI PLUG-IN There are quite a few helpful blogs discussing how to use Doctrine with CI. My preference is to use Doctrine as a CI Plug-in, which seems to make the most sense within the MVC framework. The Doctrine site discusses integrating Doctrine with CI but has you hacking the CI system code to do it. DON'T DO THIS! Doctrine works just fine as a CI plug-in without your having to hack it into the system code. First, download the Doctrine source files from the Doctrine website at http://www.doctrine-project.org/projects/orm/download. (Don't bother with their SVN if you're not using SVN, most of us are using GitHub or BitBucket anyway these days.) Unpack the Doctrine-1.2.x folder into your CI /application/plugins folder. Rename it simply "Doctrine". (This allows you to upgrade the plug-in later without changing path code deeper within your application.) You should now have within your plugins folder a /Doctrine/lib/Doctrine/ ... directory tree that contains all of the Doctrine files. Now we're going to create the Doctrine CI plug-in file which will act as our Doctrine "bootstrap" file and initialization code. This file lives in the root of the /plugins directory and will be named appropriately, doctrine_pi.php To give credit where credit is due, some of this I borrowed from Burak at PHP and Stuff Code: <?php Finally, within in your concrete controller you'll need to add this code: Code: class Some_Controller extends Controller Now Doctrine is fully available for us to use within our models. Very cool. In my next post, I'll show how to create some basic tables using Doctine's YAML config code, use UUID's and build a related table -- and ALL without writing a single line of SQL! Good stuff ... stay tuned. |
Messages In This Thread |
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 07-11-2010, 07:37 AM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 09-27-2010, 09:16 AM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 10-29-2010, 01:51 PM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 10-30-2010, 01:50 PM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 10-30-2010, 01:53 PM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 10-30-2010, 02:50 PM
WebTigers: Working with Doctrine ORM, Part 1 - by El Forum - 11-01-2010, 05:00 AM
|