Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter + Doctrine + HMVC
#1

[eluser]jwright[/eluser]
(This topic started in another topic
CodeIgniter - Doctrine ORM Tutorial : A way of enhancing CI )

After discovering lane4's great tutorials at http://www.phpandstuff.com/ and using Doctrine with CodeIgniter, I'm now looking for a better way to make reusable modules/libraries for CodeIgniter/Doctrine. It looks like wiredesignz Modular Extensions - HMVC is a lightweight and flexible approach to extending CI to have modules. Each module can be a simple as a collection of files (models, views, controllers, etc) or as complex as an entire CI application running as a module.

When thinking about combining the two some interesting questions/issues arise. Particularly, how do we organize and install Doctrine and all the models of the application and all the models of each module to enable the full benefit of modularization and Doctrine.

Would it be possible to do something like this ?... Store some domain model classes in one module and some domain model classes in another module, but when Doctrine::loadModels is called, load both modules/models and treat everything as one domain model? (I don't know enough about Doctrine to know if this is possible)
#2

[eluser]CtheB[/eluser]
Hi,

I had a look at the other topic as well.

I have done a lot of work to make doctrine work with HMVC together.
In wiredesign's example you can use dao like this:

Code:
$dao = Doctrine_ORM::Factory('pages/pages_model');

$dao->getPage($arg1, $arg2);

Its better to not call it $dao, but for instance $pages for this module.

But use it like this way, you will alway come in some trouble.
Try to generate your models into some SQL schema, and it will not work for you.

Beleave me, i worked with doctrine for many weeks.
I made my whole application work with doctrine.

But the conclusion after i had everything set up:

The overhead is to much. Doctrine is making everything so slow. You're stuck with big objects.
Even after optimizing everything. It's like 4 times slower than making your own light-weight ORM.

It's ok to try doctrine. Maybe it works for you. But i think one of the most important reasons for YOU to choose for CodeIgniter is
that it is lightweight and very very fast.

And because of this reason, you should not go with doctrine.

Oke what else do you think?

You should definitly go with PDO.

You can make it work easily together with HMVC.

Just make some modifications to the Controller.php in your application/libraries
Look for the method database()
Make some modification's to it and it works very smoothly.
You should also make a singleton method in Controller.php so you know for sure 1 PDO instance only per database connection is
returned.

If you have everything working you can try out PDO and you can see yourself it works very fast.
You don't even NEED anything from the system/database drivers... this is speeding up your application even more.

I know for sure, if codeigniter becomes PHP5, the guys behind it will drop the database drivers and work with PDO.

NOW for the ORM part: If you want to take a professional approach and make your application as fast as possible,
don't go for an existing ORM because the overhead is not where you are looking for.

Make your own factory classes into some nice libraries. Let it extend the Controller so you have it in the codeigniter way.

For each situation you can use the best factory class. Try to make use of some magic methods like __call or __set & __get
to set and retrieve values automatically. Also make use of Lazy Initialization (http://www.martinfowler.com/eaaCatalog/lazyLoad.html)

I wish you good luck with doctrine, and when you come to the point you know doctrine and codeigniter is not a good marriage after all. If you need some more help, you can always ask. But if you want to use doctrine, use symfony or some other overhead-framework.

Have a nice day.
#3

[eluser]M4rc0[/eluser]
[quote author="CtheB" date="1259856200"]Hi,
You should definitly go with PDO.

You can make it work easily together with HMVC.
[/quote]

Hello CthedB,

Could you clarify the use of PDO with CodeIgniter ?
What is PDO? Do you have any examples?
#4

[eluser]jwright[/eluser]
CtheB thanks for your recommendations. One of the aspects of CodeIgniter I like is that it facilitates rapid application development and helps me get off the ground on a project faster. Using CodeIgniter and Doctrine I've found it provides the benefit of building more advanced applications faster and with cleaner code. That being said, surely you are correct that there is a lot of overhead with Doctrine, even when optimizing it. I would agree that for certain projects like scalable web applications, CodeIgniter + Doctrine may not be a good choice. But for certain applications that there may never be masses of users for, I think the benefit of building an application faster and easier out weighs the performance hits.
Also for one web application I've built using it, I plan to try CodeIgniter's page caching if the traffic gets too much. For this particular app, the data will stay the same once it is enter so each page won't change very often.

I'm very interested to learn of other frameworks and approaches to extending CodeIgniter that are better with performance though. I second M4rc0 if you could provide some examples of PDO that would be great. I see PDO here http://php.net/manual/en/book.pdo.php but there there doesn't seem to be any full examples of how to use it that I can find.

Also, another drawback I've found in using CodeIgniter and Doctrine is that you can't see any db queries in CI's profiling because Doctrine isn't using CI's db classes. The profiling in CI is great but this is given up when using it with Doctrine.
#5

[eluser]hung5s[/eluser]
How about Igniter Record ? I think Doctrine is too heavy if your app is not really database oriented.

Doctrine helps you make RAD but if you like RAD then CI might not be the best choice. We are thinking about adding tools to CI and then make our RAD work while other PHP frameworks already have those tools. So I prefer let CI simple as it is and add only lightweight tools to facilitate what I need.
#6

[eluser]M4rc0[/eluser]
Looks like Igniter Record is now Rapid Data Mapper

This one looks much faster than Doctrine and is worth taking a look.

I'm still very interested in PDO, though.
Where are you CtheB? Smile
#7

[eluser]hung5s[/eluser]
RapidDataMapper looks potential and I plan to try it soon. ORM layer likes machine gun for your battles but you go hunting with PDO. Totally agree with CtheB and I use both.

This can be an interesting idea for PDO as data access layer: http://www.phpmadesimple.info/2008/02/10...using-pdo/
#8

[eluser]Devon Lambert[/eluser]
Hello Wrightlabs did you ever get this to work in Modular fashion?

I have had Doctrine running for quite some time. I even managed to convert Tank Auth for the use of Doctrine but I when introducing new models I want to add the ability to keep my doctrine models in the module_name/models folder as opposed to grouping all of Doctrine's models in one folder, and then having all those models auto loaded (conservatively) as necessary.

I suspect this may not be possible and haven't had the opportunity to test at any great lengths, but so far, I can honestly say that Doctrine was meant for CI. Don't let the nay sayers get you down.

Cache is your friend and so is DQL.
#9

[eluser]easylancer[/eluser]
[quote author="Devon Lambert" date="1265420113"]Hello Wrightlabs did you ever get this to work in Modular fashion?

I have had Doctrine running for quite some time. I even managed to convert Tank Auth for the use of Doctrine but I when introducing new models I want to add the ability to keep my doctrine models in the module_name/models folder as opposed to grouping all of Doctrine's models in one folder, and then having all those models auto loaded (conservatively) as necessary.

I suspect this may not be possible and haven't had the opportunity to test at any great lengths, but so far, I can honestly say that Doctrine was meant for CI. Don't let the nay sayers get you down.

Cache is your friend and so is DQL.[/quote]

You mind sharing the library of Tank Auth using Doctrine ORM please?
#10

[eluser]Devon Lambert[/eluser]
[quote author="easylancer" date="1270784143"]You mind sharing the library of Tank Auth using Doctrine ORM please?[/quote]

And here ya go. :-)




Theme © iAndrew 2016 - Forum software by © MyBB