Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: 1.x
Fetching contributors…

Cannot retrieve contributors at this time

150 lines (97 sloc) 4.772 kb

PropelServiceProvider

Build Status

The PropelServiceProvider provides a Silex integration with Propel.

Branching model

  • The 1.x branch contains Propel 1.6 integration.
  • The 2.x branch contains Propel2 integration.

Note: the following instructions are relative to PropelServiceProvider used with Propel 1 (branch 1.x). For PropelServiceProvider used with Propel2, please switch to branch 2.x.

Set up

If you want to use PropelServiceProvider, you will need:

  • Silex 1.x
  • PHP 5.4 or greater
  • Composer

To setup the project in your Silex application, you have to rely on composer ; just add the following to your composer.json file:

"require": {
    "propel/propel-service-provider": "1.x"
}

Then run php composer.phar install to install it!

Parameters

  • propel.path (optional): The path in wich Propel.php will be found. Usually, for PEAR installation, it is propel while for Git installation it is vendor/propel/runtime/lib. Default is /full/project/path/vendor/propel/propel1/runtime/lib.

  • propel.config_file (optional): The name of Propel configuration file with full path. Default is /full/project/path/build/conf/projectname-conf.php

  • propel.model_path (optional): Path to where model classes are located. Default is /full/project/path/build/classes

It's strongly recommanded to use absolute paths for previous options.

Services

No service is provided.

Propel configures and manages itself by using static methods, so no service is registered into Application. Actually, the PropelServiceProvider class initializes Propel in a more "Silex-ian" way.

Registering

Make sure you place a copy of Propel in vendor/propel or install it through PEAR, or Composer.

For more informations consult the Propel documentation:

<?php

$app['propel.config_file'] = __DIR__.'/path/to/myproject-conf.php';
$app['propel.model_path'] = __DIR__.'/path/to/model/classes';
$app->register(new Propel\Silex\PropelServiceProvider());

Alternatively, if you 've installed Propel by Git in vendor/propel and you built your model with default Propel generator options:

<?php

$app->register(new Propel\Silex\PropelServiceProvider());

We can consider "default" Propel generator options:

  • Put build.properties and schema.xml files into the main directory project, usually where file index.php is located.

  • In build.properties file, define only propel.database, propel.project and propel.namespace.autopackage properties.

Usage

You'll have to build the model by yourself. According to Propel documentation, you'll need three files:

  • schema.xml which contains your database schema;

  • build.properties more information below;

  • runtime-conf.xml which contains the database configuration.

Use the propel-gen script to create all files (SQL, configuration, Model classes).

By default, the PropelServiceProvider relies on the Silex autoloader you have to configure to load model classes. Of course, the Silex autoloader needs the model to be built with namespaces, so be sure to set this property into the build.properties file:

propel.namespace.autopackage = true

The recommended configuration for your `build.properties` file is:

propel.project      = <project_name>

propel.namespace.autoPackage = true
propel.packageObjectModel    = true

# Enable full use of the DateTime class.
# Setting this to true means that getter methods for date/time/timestamp
# columns will return a DateTime object when the default format is empty.
propel.useDateTimeClass = true

# Specify a custom DateTime subclass that you wish to have Propel use
# for temporal values.
propel.dateTimeClass = DateTime

# These are the default formats that will be used when fetching values from
# temporal columns in Propel. You can always specify these when calling the
# methods directly, but for methods like getByName() it is nice to change
# the defaults.
# To have these methods return DateTime objects instead, you should set these
# to empty values
propel.defaultTimeStampFormat =
propel.defaultTimeFormat =
propel.defaultDateFormat =

If you plan to build your model without using namespaces, you need to force Propel to use its internal autoloader. Do this by setting the option propel.internal_autoload to true.

For more information, consult the Propel documentation.

Jump to Line
Something went wrong with that request. Please try again.