Pergunta

I just discovered PHP-ActiveRecord not too long ago after struggling for nearly a month to write my own ORM (I'm hard headed like that) and I fell in love with it. I had looked at Doctrine and Propel before but decided to run away due to the sheer complexity and learning curve. With AR, I don't have the anxiety and learning difficulty I had with the others.

Shortly thereafter, I also discovered the symfony framework (I was also trying to make my own framework from stratch after finding other frameworks overly bloated). However, I have one issue: the symfony framework using Doctrine and Propel as an ORM/abstraction layer out of the box without any documentation on how to change it.

I haven't actually used symfony yet, I've been reading the "Gentle Introduction" book. The ORM/abstraction layer seems somewhat removed from the core of symfony and seems to be easy enough to convert everything over. The question is... is it?

Does anyone have any sort of experience using ActiveRecord with symfony or, even, using anything other than Doctrine/Propel with symfony?

Foi útil?

Solução

I would bundle the ActiveRecord code as a Symfony plugin. You can read more about creating Symfony plugins here. The basics would be:

  • Create an plugins/sfActiveRecordPlugin folder. Put the active record code in plugins/sfActiveRecordPlugin/lib/vendor.
  • Put whatever bootstrapping ActiveRecord needs inside sfActiveRecordPlugin/config/config.php. This code will get executed every time a ProjectConfiguration is instantiated. If ActiveRecord has it's own autoloader, you'll probably need to resolve that here. You may also need to set Symfony to ignore the ActiveRecord classes, this is done via autoload.yml.
  • Enable your plugin in your ProjectConfiguration class:

    class ProjectConfiguration extends sfProjectConfiguration
    {
      public function setup()
      {
        $this->enablePlugins(array(
          'sfActiveRecordPlugin',
        ));
      }
    }
    

    The enable plugins call will disable any plugins not explicitly enabled. You can also call disablePlugins with the plugins you do not want loaded, if you prefer.

That should be most of the work.

Finally, I would urge you to give Doctrine another shot. Doctrine is a very powerful ORM and IMO is the best one out there. In addition, Symfony comes with a lot of Doctrine specific stuff that you're going to end up rewriting at least some of.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top