Hi,
I’m searching for a way to load the whole modx thing in a file that I use for a module.
Since the file sits in /assets/modules/my-module/file.php and I access it with Ajax, I would like to use Modx’s CMS capability instead of making my own connection to the db.
I could not find a tutorial of what files I need to include at top so I can use $modx->db->connect() and the rest of the db APIs.
I guess something like this was posted before but I could not find it.
Thank You
-
MODX Staff
- 10,725 Posts
Modules already have access to $modx and the database connection. All you need to do is handle the requests from the module. A module is nothing more than a simple view controller to handle requests made to the module, regardless of what those requests are ultimately calling. Simply include your external file based on appropriate links generated by/for your module.
So if I want to post some kind of info I need to submit it to the same page not to another page?
Eg: manager/index.php?a=112&id=2&action=delete&id=3
...and create the logic in the module.
I might be wrong but Sottwell’s tutorial does not load modx into her/his files. She/He uses plain PHP.
Works for me too, but I wanted a way to use modx APIs.
Since I have to do a simple delete I will probably go with Sottwell’s solution.