简体   繁体   English

有没有一种方法可以将PHP-ActiveRecord用作symfony的ORM /抽象层?

[英]Is there a way of using PHP-ActiveRecord as symfony's ORM/abstraction layer?

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. 在奋斗近一个月来编写自己的ORM之后,我才发现PHP-ActiveRecord。 I had looked at Doctrine and Propel before but decided to run away due to the sheer complexity and learning curve. 我之前看过《学说》和《 Propel》,但由于其复杂性和学习曲线而决定逃跑。 With AR, I don't have the anxiety and learning difficulty I had with the others. 使用AR,我不会像其他人那样感到焦虑和学习困难。

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). 此后不久,我还发现了symfony框架(在发现其他框架过分膨胀之后,我也试图从stratch中创建自己的框架)。 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. 但是,我有一个问题:使用Doctrine和Propel作为ORM /抽象层的symfony框架开箱即用,而没有任何有关如何更改它的文档。

I haven't actually used symfony yet, I've been reading the "Gentle Introduction" book. 我实际上还没有使用过symfony,我一直在阅读“ Gentle Introduction”一书。 The ORM/abstraction layer seems somewhat removed from the core of symfony and seems to be easy enough to convert everything over. ORM /抽象层似乎已从symfony的核心中删除,并且似乎很容易将所有内容转换。 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? 有没有人有将ActiveRecord与symfony一起使用的经验,甚至没有将教义/ Propel与symfony一起使用的经验?

I would bundle the ActiveRecord code as a Symfony plugin. 我将ActiveRecord代码捆绑为Symfony插件。 You can read more about creating Symfony plugins here . 您可以在此处阅读有关创建Symfony插件的更多信息。 The basics would be: 基础是:

  • Create an plugins/sfActiveRecordPlugin folder. 创建一个plugins/sfActiveRecordPlugin文件夹。 Put the active record code in plugins/sfActiveRecordPlugin/lib/vendor . 将活动记录代码放在plugins/sfActiveRecordPlugin/lib/vendor
  • Put whatever bootstrapping ActiveRecord needs inside sfActiveRecordPlugin/config/config.php . 将引导ActiveRecord所需的任何内容放入sfActiveRecordPlugin/config/config.php This code will get executed every time a ProjectConfiguration is instantiated. 每次实例化ProjectConfiguration时,都会执行此代码。 If ActiveRecord has it's own autoloader, you'll probably need to resolve that here. 如果ActiveRecord拥有自己的自动加载器,则可能需要在此处解决。 You may also need to set Symfony to ignore the ActiveRecord classes, this is done via autoload.yml . 您可能还需要将Symfony设置为忽略ActiveRecord类,这是通过autoload.yml完成的。
  • Enable your plugin in your ProjectConfiguration class: ProjectConfiguration类中启用插件:

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

    The enable plugins call will disable any plugins not explicitly enabled. enable plugins调用将禁用所有未显式启用的插件。 You can also call disablePlugins with the plugins you do not want loaded, if you prefer. 如果愿意,还可以使用不想加载的插件调用disablePlugins。

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. 主义是一种非常强大的ORM,而IMO是最好的ORM。 In addition, Symfony comes with a lot of Doctrine specific stuff that you're going to end up rewriting at least some of. 另外,Symfony附带了许多特定于教义的东西,您至少要重写其中的一些东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM