The xPDO Constructor

Parameters

As you can see, there are 5 parameters available in the constructor; the only necessary one is the first:

$dsn

This parameter asks you for your DSN value, which is formatted like so:

mysql:host=MYHOSTNAME;dbname=MYDBNAME;charset=MYCHARSET

You'll simply have to change the values of the hostname, database name, and charset to set up the parameter. More info can be found at PHP.net's PDO page.

$username & $password

This is the username and password to the database. Simply specify the database login information you'd like to use for xPDO's connections.

$options

This allows you to pass an array of xPDO-specific options into the constructor.

Some of the xPDO-specific parameters use custom defines that you can use, such as (but not limited to):

  • XPDO_OPT_TABLE_PREFIX - If set, all database class references will be prefixed with this prefix.
  • XPDO_OPT_CACHE_PATH - If set, will set a custom cachePath class variable to the xPDO object that can be used in caching.
  • XPDO_OPT_HYDRATE_FIELDS - If true, fields will be hydrated.
  • XPDO_OPT_HYDRATE_RELATED_OBJECTS - If true, related objects will be hydrated.
  • XPDO_OPT_HYDRATE_ADHOC_FIELDS - If true, ad-hoc fields will be hydrated.
  • XPDO_OPT_BASE_PACKAGES - A comma-separated string of package names/paths (separated by a colon) to be loaded upon instantiation.
  • XPDO_OPT_BASE_CLASSES - An array of classes to load upon instantiation.
  • XPDO_OPT_LOADER_CLASSES - Can be an array of class names to load upon instantiation of the xPDO object.
  • XPDO_OPT_VALIDATOR_CLASS - If set, will use a custom class specified that derives from xPDOValidator (the default)
  • XPDO_OPT_VALIDATE_ON_SAVE - If true, xPDOObjects will be validated against their Validators before saving.

$driverOptions

An optional array of driver-specific PDO options. More info can be found here.

See Also

  1. Hydrating Fields

Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).