Jump to main content Jump to doc navigation

extension_packages

Name: Extension Packages Type: String(a JSON encoded array of key value pairs) Default: Yes

Use this setting to autoload packages that extend core classes, e.g. if you are extending modUser. The format should be a JSON array of key/value pairs where the key is the namespace (i.e. the package name) and the value is the path to its model.

This effect here is similar to other frameworks, e.g. CodeIgniter, which allows core classes to be overridden via use of a special classname prefix "MY_".

Use this only when you are extending core classes that are used during initialize()

Sample value

[{"extendeduser":{"path":"[[++core_path]]components/extendeduser/model/"}},{"articles":{"path":"[[++core_path]]components/articles/model/"}}]

You can make use of the

[[++core_path]]

placeholders.

Another Example

If your extension uses a different table prefix, you should list this in your JSON by using the tablePrefix key, e.g.

[{"extendeduser":{"path":"[[++core_path]]components/extendeduser/model/","tablePrefix":"ext_"}},{"articles":{"path":"[[++core_path]]components/articles/model/"}}]

At some point in the recent version history, the addExtensionPackage and removeExtensionPackage convenience functions were added to facilitate adding and removing data to the extension_packages setting.

addExtensionPackage

boolean addExtensionPackage ([string $pkg = ''], [string $modelpath = ''], [array $options = array()])

The $pkg argument really specifies a subfolder in the named model directory. In most packages, this name is the same as the package's namespace, but other packages may specify multiple sub-folders in their model. Note that the $options array can specify a "tablePrefix" key, e.g.

$modx->addExtensionPackage('mypkg', '/path/to/core/components/mypkg/model/', array('tablePrefix'=>'mypre_'));

removeExtensionPackage

When it's time to clean up, remove your node from the extension_packages array using this convenience function:

boolean removeExtensionPackage (string $pkg = '')

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more