forrest lyman Thu Jan 27 23:25:11 -0500 2011

Subject: zend framework integration

I really like what you have all done with this project. I have written a couple simplistic PHP AR solutions but all before late static bindings, so they had some arguably hacky workarounds.

I played around with this a bit and wrote a Zend application resource to basically integrate it:

class Dig_Application_Resource_Activerecord extends Zend_Application_Resource_ResourceAbstract
    public function init ()
        $options = $this->getOptions();
        $cfg = ActiveRecord\Config::instance();
        // we are going to let zf handle the app environment rather than handing this off to ar
        $cfg->set_connections(array(APPLICATION_ENV => $this->connection($options['params'])));

    public function connection($params) {
        return 'mysql://' . $params['username'] .
                    ':' . $params['password'] .
                    '@' . $params['host'] .
                    '/' . $params['dbname'];

You can then add activerecord support to your app with this in the application config file:

resources.activerecord.path = "/path/to/php-activerecord/ActiveRecord.php" 
resources.activerecord.params.username = "root" 
resources.activerecord.params.password = "" = "localhost" 
resources.activerecord.params.dbname = "my_database"