How to Zend Framework with Propel ORM
Asked Answered
P

4

9

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?

Perilune answered 26/9, 2010 at 0:18 Comment(0)
S
11

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

Separative answered 26/9, 2010 at 2:44 Comment(2)
How do I adapt to ini? I have no ideaBasket
@rodrigo: it should be a fairly easy translation since the structure isnt complex... i think you can parse the constants directly in the INI so all you have to do is use the key value pairs int eh correct section. Then again i could be wrong, i never use INI format. If you cant figure it out i would post a new question about it... youll get more of a response that way :-)Separative
G
4

Have you tried

Glorification answered 26/9, 2010 at 0:55 Comment(1)
Yes, They're from 2006 and 2008. Zend has changed a lot.Perilune
D
1

I place the Propel library in "Your Zend_Project/library" with a folder called Propel which has the runtime folder in it.

I then place this chunk of code in my bootstrap.php.

protected function _initPropel()
{
   //require Propel Library
   require '../library/Propel/runtime/lib/Propel.php';

   //initialize Propel configuration
   Propel::init(APPLICATION_PATH . '/configs/orm-conf.php');

   //initialize Propel connection
   Propel::initialize();

   //return Propel Connection
   return Propel::getConnection();

}

My Propel config files are in the "Your Zend Project/application/configs"

You also need to modify your index.php file so it will find the ORM models you have generated:

set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), realpath(APPLICATION_PATH . '/models'), get_include_path(), )));

You place your models in the Your "Zend Project/application/Models/database" name which is set in your schema.xml by the xml property in "database name="orm"" tag.

Disrepair answered 22/2, 2012 at 21:9 Comment(0)
S
1

Just try to add init of propel to index.php file but BEFORE you set up autoload process. In this case Zend_Autoloader cannot interact with Propel autoloading mechanism. For me it work fine, but i'm not sure it it a good design...)

Solomonsolon answered 8/5, 2012 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.