如何使用Propel ORM来构建框架

jbl*_*lue 9 php orm propel zend-framework

我想整合PropelZend framework.我在过去看到了学说的整合,但是这篇文章说看起来似乎有点不同.

Propel已经有两件事了:第一件事Propel包括它自己的自动加载器,这意味着我不必尝试强制Propel进入Zend Framework文件系统结构.第二个是Propel为了让你轻松地将它的文件放在你想要的任何地方,只要你include path正确更新.这使得这个过程比我想象的要容易得多.

但该帖子没有详细介绍如何完成它.我猜我不得不修改Zend Bootstrap.phpapplication.ini(我使用的是最新的Zend 1.10.8),但我发现很难找到的最新版本后Zend使用的最新版本Propel.

任何人都可以用最流畅的方式评论如何做到这一点?

另一个问题:确实Propel有一个命令行界面,或者如果我使用命令行界面,我不需要推进命令行界面Zend

pro*_*son 11

我没有在Symfony之外使用Propel,但是从我所知道的Propel中我会想到以下内容对于运行时的东西会起作用:

在你的引导程序中

public function initPropel()
{
   require_once 'Propel.php';
   Propel::init($this->getOptions('propelConfig'));

   // so we can get the connection from the registry easily
   return Propel::getConnection();
}
Run Code Online (Sandbox Code Playgroud)

在你的application.xml中(如果你喜欢那就适应ini)

<applicationConfiguration xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
  <production>
    <!-- other stuff -->
    <includePaths>
        <propelRuntime><zf:const zf:name="APPLICATION_PATH" />/../library/propel/runtime</propelRuntime>
    </includePaths>
    <propelConfig><zf:const zf:name="APPLICATION_PATH" />/configs/propel-runtime.php</propelConfig>
    <!-- other stuff -->
  </production>
</applicationConfiguration>
Run Code Online (Sandbox Code Playgroud)

当然,就我而言,这并不是真正完全集成......但它应该足以让你在没有太多麻烦的情况下运行起来.如果它值得您在这个项目上投资,我会继续做一个应用资源.运行推进构建并查看已编译的php数组.然后将其映射到xml或ini并将其直接嵌入到应用程序配置文件中.然后修改你initPropel的处理方式如下:

public function initPropel()
{
   require_once 'Propel.php';
   Propel::setConfiguration($this->getOptions('propelConfig'));
   Propel::initialize();

   // so we can get the connection from the registry easily
   return Propel::getConnection();
}
Run Code Online (Sandbox Code Playgroud)

如果你想要甚至不能直接加载从配置文件解析的数组,而是创建一个PropelConfiguration对象并以编程方式设置所有参数,然后将其传递给setConfiguration.

至于构建工具,我发现与Zend_Tool集成是一个考验,所以我倾向于依赖phing或自定义shell脚本.除非您计划在许多项目上使用Propel,否则可能没有时间来实现这种级别的集成.我在回来的时候用Doctrine 1.xa做了这件事,我花了几个星期的时间来解决所有问题:-)