I’ve never been so happy in my life…
until now – American Idol is finally over. Thank you.
5 sets of 5 at 300 lbs
So, I have been ramping up on my lifting to prepare for a shot at a new bench max in the next month or so (currently 375). Actually, I have not been lifting any more regularly, just bumping up the weight and doing less bench reps and more weight. On Monday I did 5 sets of 5 at 300 lbs, which is a new best for me at that set/rep count. I also did 315 4 times which is the most reps I have ever done at that weight. So… here hoping for 380+ in June. The goal is 400 before the end of the year… ouch, that is going to hurt!
Zend Framework and Propel


This information may or may not be meaningful to anyone but me. I was new to Zend Framework and Propel, so attempting to get them to place nice was twice the undertaking. I am happy to report that all went relatively smoothly.
The first problem I encountered was just getting Propel to do what I wanted since I had 2 databases I was dealing with. I have a ‘global’ database and also a ‘local’ database. The local database actually is one of several dbs that all share the same schema, but is simply specific to which customer is using the system. The global db is, well, global to the application.
Here is a copy of my runtime-conf.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<config>
<propel>
<datasources default="global">
<datasource id="local">
<adapter>mysql</adapter>
<connection>
<dsn>mysql:host=localhost;dbname=local</dsn>
<user>localuser</user>
<password>localpass</password>
<settings>
<setting id="charset">utf8</setting>
</settings>
</connection>
</datasource>
<datasource id="global">
<adapter>mysql</adapter>
<connection>
<dsn>mysql:host=localhost;dbname=global</dsn>
<user>globaluser</user>
<password>globalpass</password>
<settings>
<setting id="charset">utf8</setting>
</settings>
</connection>
</datasource>
</datasources>
</propel>
</config>
The next thing was to get my schema files setup for each database. I created a global-schema.xml and a local-schema.xml. Below you will see the database node lines, which is all that really needed manipulation.
<database name="global" heavyIndexing="true" defaultIdMethod="native" package="orm.global">
<database name="local" baseClass="hvBaseClassLocal" heavyIndexing="true" defaultIdMethod="native" package="orm.local">
Make sure that you specify the package names. This will result in the following file structure:
orm
global
{generated class files}
local
{generated class files}
Note above that I am specifying hvBaseClassLocal as the baseclass. This will make all generated class files extend from my hvBaseClassLocal class. This is great functionality if you have common methods you want available for all your classes (logging, etc).
Before you propel-gen you will want to make sure the files are going to be where and how you want them. This is specified in build.properties.
build.properties
propel.project = safetrax
propel.database = mysql
propel.targetPackage = orm
propel.mysql.tableType = InnoDB
propel.home = .
propel.projhome = /Users/jhansen/Sites/safetrax-zend
propel.output.dir = ${propel.projhome}/application/models
propel.schema.dir = ${propel.projhome}/config/schema
propel.conf.dir = ${propel.projhome}/config/conf
propel.phpconf.dir = ${propel.projhome}/config/conf
propel.sql.dir = ${propel.projhome}/config/sql
propel.runtime.conf.file = runtime-conf.xml
propel.php.dir = ${propel.projhome}/application/models
Note that there is no database connection information there. That info is used if you are going to have propel create your schema files for you (not recommended) or you want propel-gen to manage rebuilding the schema in your databases. It works fine when you have one database, but as soon as you add the second you are hosed, as it can only do one at time… therefore you end up hacking the file and running propel-gen again. So, we just avoid that whole mess by creating our schema.xml files manually and using a separate means for dealing with the databases you will see next.
Ok, next step is to run propel-gen script. This will go ahead and created all your object class files and peer classes. I wrote a little shell script that I use for development that does at bit more:
#!/bin/bash
propel-gen .
echo "DB Destroy & Recreate...";
mysql -u root -pmypassword < config/sql/setup.sql
echo "DB Loading Schema...";
mysql -u globaluser -pglobalpassword global < config/sql/global-schema.sql
mysql -u localuser -plocalpassword local < config/sql/local-schema.sql
echo "Loading Fixtures...";
cd config/fixtures; php populate.php;
echo "Done"
My setup.sql looks like this:
DROP DATABASE IF EXISTS `local`;
DROP DATABASE IF EXISTS `global`;
CREATE DATABASE `local` ;
CREATE DATABASE `global` ;
So, in essence when I execute ./regen.sh my databases are completely destroyed and recreated using setup.sql. Then the schema for both databases is loaded back in using the sql files generated from propel-gen. The next step is running populate.php which is a script I wrote for loading up fixtures that I need in place while in development.
populate.php
<?php
// Set the include
set_include_path("../../application/models" . PATH_SEPARATOR .
"../../application/models/orm" . PATH_SEPARATOR .'../../library' .
PATH_SEPARATOR . get_include_path());
include_once '../../library/hvTools.class.php';
include_once("propel/Propel.php");
Propel::init("../../config/conf/safetrax-conf.php");
$u = new User();
$u->setName("Jeff Hansen");
$u->save();
?>
Populate.php keeps getting larger as I add new objects to the project and load them up when regenerating. I have become very fond of this approach as it tests your code while it is working, therefore you will know right away if you have errors in any overloaded save methods or others that do more than just set attributes on the objects.
The last thing to do is to start acutally integrating this baby w/in the Zend Framework. This really couldn’t be easier. Open up your bootstrap file – index.php and add the following (adjust paths as necessary.):
index.php
set_include_path('.' . PATH_SEPARATOR . '../library' . PATH_SEPARATOR . '../application/models'. PATH_SEPARATOR . '../application/models/orm' . PATH_SEPARATOR . get_include_path());
include_once("propel/Propel.php");
Propel::init("../config/conf/safetrax-conf.php");
That’s it! Byahh! You will now be able to access your classes from both databases in a sane fashion. Below is an image of my project layout in Zend Studio for Eclipse. Click on it for full size.
If you have any questions feel free to ask.
