I want to create a file, say foo.php, that when called, accesses the MODx API, e.g. uses the DBAPI, grabs some data and returns an xml file.
This file will be called directly by the browser, i.e. not from within a snippet or the manager.
Is it possible to do this, and if so what do I need to include to gain access to the API?
Andy
-
MODX Staff
- 10,725 Posts
This is not really a good idea at the moment, with the size of the file you would be including, but you can see the code in index.php that instantiates the DocumentParser class into the $modx object if you still want to do this currently. It’s just a lot of overhead to load if you only need one or two calls into the API, and certain parts can conflict with things in other scripts, depending on what that script does and how it does it.
In this regard, 1.0 will have a much more modular, compact, and distinct set of API’s that can be loaded only when needed (i.e. on demand), classes extended and methods overridden without hacking core files, etc. This means you could use (or even customize) just the parts of the MODx framework you want, very easily in stand-alone PHP pages, WordPress plugins, and just about any other PHP script or application you wanted to with minimal impact on the other scripts (or worrying about future upgrade paths).
I’m curious, is it just the DBAPI portion you want access to?
The nice thing about MODx is that there is more than one way to do things. I decided to do the following:
Create a non-cached page called markers
Set the page content type to text/xml
Create a single snippet for the page, also called markers
Edited the snippet to return XML
Works great. Might be a bit slower, but it keeps all the editing for the site in the manager, rather than having to use SSH for this one aspect.
Andy