Blog Sections Open

Using MODX API Functions from an External PHP File

If an external PHP script needs MODX or Evolution CMS functions, bootstrap the CMS first instead of trying to call API helpers in isolation.

Export scripts, cron jobs, and integration endpoints often begin as standalone PHP files. The moment they need MODX API calls, they must be loaded through the CMS bootstrap instead of assuming the global environment already exists.

The principle

Your external file should include the CMS bootstrap, then work through the initialized API object just like a snippet or module would.

Recommendation

Do not duplicate database logic in standalone files if the CMS already owns the data model. Bootstrap the environment, use the API deliberately, and keep external scripts thin.

Newer post

Building Dependent Filters in Evolution CMS

Dependent filters are easiest to reason about when each selection narrows the available values for the next step instead of trying to solve everything in one giant query.

Older post

Preserving the Manual Order of documents in Ditto

If you pass a manual list of resource IDs into Ditto, you often need to keep that custom order instead of letting default sorting rearrange the results.