Quote from: dev_cw at Apr 12, 2008, 09:44 AM
Just thinking out loud, I know nothing about this stuff...but I thought that all you needed was to declare "global $modx;" to bring the api into scope.
Ehm, no, because the page that serves the ajax response can’t simply "get the global $modx". This page is not loaded inside the manager (in that case, you simply need to call the global $modx to get it). The page is "alone", and to use $modx you need to include the class (and the config file, to get the link to the db).
Quote from: ganeshXL at Apr 12, 2008, 09:59 AM
I think it depends on how you build (include) your module:
If you embed it via iframe, you have to do all that import/include stuff, because to PHP, it’s just a separate page (only visually "merged" in your browser).
The page is not viewed inside the manager. Well, the module IS actually in the manager (as other modules) but when you do an ajax call you need a page that is not "inside" the manager. It’s only a php page, and if you don’t include the document parser class and the site config you can’t use the modx api at all. Obviously I may create a db link inside the page itself and retrieve information in a common php-mysql way, but I
want to use the power of the modx framework, that’s what a framework is create to do.
Quote from: ganeshXL at Apr 12, 2008, 09:59 AM
If you use PHP’s include(’myModule.php’) you don’t even need to declare global $modx - you are already inside the manager, and MODx does the magic for you.
This method is unsuitable for this situation because your module pages are in the manager but only when you load it in the manager. It’s the manager that eval()s your page, not your page that has a $modx = new DocumentParser. The manager takes care of giving your module the power of modx api at the cost of a "global modx" declaration. Basically, including your module page doesn’t get the api, because the link to the api is not in your page but in the manager itself.
I don’t know if I was sufficiently clear