Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Zend Framework with Propel ORM

I'd like to integrate Propel with Zend framework. I've seen the integration of doctrine in the past but this post says it seems propel is done a bit differently.

Propel has two things going for it already: the first is that Propel includes its own autoloader, meaning that I didn't have to try and force Propel into Zend Framework’s file system structure. The second is that Propel is designed to let you put it’s files anywhere you want with ease, so long as you update your include path properly. This made the process significantly easier than I had thought it would be.

But the post doesn't go into full details on how to finish it. I'm guessing I have to modify the Zend Bootstrap.php and application.ini (I'm using the latest Zend 1.10.8), but I'm finding it difficult to find a post on the latest version of Zend with the latest version of Propel.

Anyone can comment how to do this in the smoothest way possible?

another question: does Propel has a command line interface or do I not need a command line interface for propel if I'm using the command line interface of Zend?

like image 276
jblue Avatar asked Sep 26 '10 00:09

jblue


2 Answers

I havent use Propel outside of Symfony but from what i know of Propel but i would think something like the following would work for the runtime stuff:

In your bootstrap

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();
}

In your application.xml (adapt to ini if thats what you prefer)

<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>

Of course this isnt really full integration as far as im concerned... but it should be enough to get you up and running without a lot of hassle. If its worth the investment to you on this project i would go ahead and make an Application Resource. Run a propel build and take a look at the compiled php array. Then map that to xml or ini and embed it directly in your application config file. Then modify your initPropel to handle it like:

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();
}

If you wanted you could even not directly load the array as parsed from the configuration file but instead create a PropelConfiguration object and programtically set all your parameters, then pass that to setConfiguration.

As for the build tools, ive found integrating with Zend_Tool to be an ordeal so i tend to rely on phing or custom shell scripts for all that. Unless you plan on using Propel on a lot of projects its probably not with the time to implement this level of integration. I did it with Doctrine 1.x a while back and it took me a couple weeks to work all the kinks out :-)

like image 164
prodigitalson Avatar answered Oct 13 '22 14:10

prodigitalson


Have you tried

  • Integrating Propel with the Zend Framework
  • Zend Framework and Propel
  • Integrating Propel with the Zend Framework
like image 39
Pramendra Gupta Avatar answered Oct 13 '22 15:10

Pramendra Gupta