Can I use the Yii ORM without the rest of the framework?

I’ve dived in and tried to do this naively, but there seems to be a chain of more and more core requirements, and I’m wondering if by including the needed files I’m initialising much more of the central framework than I actually want.

Even if the answer to “Is this possible?” is “Yes”, is there so much extra stuff I’m pulling in that it just makes it a silly idea?

Should I just use Propel instead?

Many thanks!

I actually never used Yii’s orm, I always use Doctrine. It has numerous advantages over Yii’s orm (and a few over propel). The thing I like most are extensions (e.g. nestedset somewhere on github) and also your model is ‘free’ (doesn’t inherit from a propel/yii class!). Doctrine also has nice docs and design patterns (UnitOfWork).

Hi FE93,

I was kind of asking the opposite question… we have our own reasons why it might be good to use the Yii ORM for a particular project.

That said, it’d be interesting to hear why you’d opt for Doctrine over Propel. I’ve read through the initial setup instructions and tutorials for both, and it seems Propel

  1. makes fewer assumptions, making it

  2. more configurable, and

  3. doesn’t have this weird notion of “the ‘owning’ side” of a foreign-key relationship; I don’t want to have to explain to my devs that if they want to save data about an object of class X, they actually have to do it through class Y. Perhaps I’ve misunderstood Doctrine’s documentation, but that’s a show-stopper of a limitation, for me at least.

doubi

I’m afraid you’ll not be able to avoid Yii dependencies if you want to use its AR. What’s the reason no to use Yii itself?

Check out this: http://www.yiiframework.com/doc/guide/1.1/en/extension.integration#using-yii-in-3rd-party-systems

Right, but this way he’ll “initialise much more of the central framework than he actually wants”.

Most of the above doesn’t make sense to me, so unfortunately (my M.O. if you will) I cannot answer them one by one (I’m pretty sure Doctrine doesn’t make any more assumptions about your data than any other ORM :) ). I also don’t think this is the right place for propel-doctrine-yii orm pros/contras (the real question is imho: why does yii invent a square wheel and not use doctrine standard). A simple google query should answer most of your questions. I’ll give one simple (but very important!) example. Like I said your models are ‘free’: so I have a User model, which contains the annotations for doctrine, but also all scenario’s for forms. This would not be possible in Yii or propel. I could go on and on about the extra features, but I’ll suffice to say you better re-read some docs ;). If after 2 weeks of reading documentation and ploughing through code/design you still favor propel than at least you can give a reason why (like I said, above questions/statements? make little sense or are false).

To each his own!

I used both Propel and Doctrine with Symfony a few years back and used both with CodeIgniter using wrappers. Sometimes the project needs of your customers cross sabres with your personnel needs and wants. Unless someone has personal experience and more than a casual understanding of using both ORMs as well as other available solutions, it’s difficult to rank an ORM. There are of couse third-party benchmarks and reviews floating about on the web. I would check the dates on these because there a lot of outdated material on the web. Personally, I prefer Doctrine over Propel because it makes better sense to me and was a lot easier to learn the code, but use Yii’s active record on my projects for a number of reasons, a few of which are mentioned below.

Qiang probably made the same design decisions as Rick Ellis over at CodeIgniter. In order to gain ultimate control over crud generation, it was best to roll their own Active Record solution. There is also database caching support integrated into the framework for third-party solutions and to me this makes a big difference in many of my design decisions.

Aside from this, Qiang designed Yii with a hierarchy of classes in the very same way professional frameworks are developed for the commercial market, making Yii extremely extensible. Before the web, I did a lot of work with Visual C++ and for this reason feel right at home in Yii.

As you mentioned, I do miss Doctrine’s support for nested sets. But its possible to build a yiic, gii or giix template to add support to Yii, not to mention other features. I’ve been thinking about this a lot lately, but haven’t been able to find the time.

Regarding the original question. Sure it’s possible, but as you already know the solution is going to require pulling a lot of dependencies to make it possible. If you take a close look at the internals of Propel and Doctrine, you should be able to understand why. Walk your way backwards tracking through the class hierarchy to see what I mean. Maybe someday, someone with above normal patience may try to introduce an abstraction layer into the interface. In your shoes (been there), I would go with Propel or Doctrine, or take samdark’s advice about using Yii for your project.

I know there are Doctrine wrapper components on the extensions library and possibly a tutorial on the wiki. To my knowledge, I have not noticed the same for Propel.

Don’t take my word for it because I could be wrong, but I think Propel started off as a PHP4 project while Doctrine started off as a PHP5 project. In PHP5’s infancy, many a PHP4 developer migrated to PHP5 while using a lot of stale ideas and notions. If I recall, Doctrine participated and scored high in the same Zend contest that Qiang’s other framework (Prado) won shortly after PHP5 was first introduced.