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