I am getting started with Revolution Beta 5, and there are some basic concepts that I am having trouble understanding. I know the answers must be out there, but I am at a loss to find them.
I have dynamic php data loading into dialogs after buttons are pressed using jquery ajax calls. I couldn’t figure out how to call a snippet through javascript, nor could I figure out how to call a snippet with an ajax call. There doesn’t seem to be a way to get a URL to a snippet like you can for a resource.
The only way I could figure out how to load dynamic content was to use an external PHP file. I don’t have a problem with this solution, although I’m not sure that it is the best one. And it leads me to the next problem. I can’t find any revolution examples for accessing modx revo session variables from an external php file.
When I process data in my external php file, I would like to share the current modx session, and I would also like to set session variables that I can access back in modx.
I hope I’m making sense, and any nudges in the right direction would be most appreciated!
Ed Hoskins
SpinSite, Inc.
-
MODX Staff
- 730 Posts
I recommend creating a resource that contains the snippet call you need.
Then you can refer to the resource in javascript.
Select the blank template so that the snippet can return whatever it needs to, be it json or xml etc.
If I do that, can I send (post?) variables to the resource and have them passed to the snippet?
Ed
-
MODX Staff
- 730 Posts
Sure, your snippet can read the POSTed variables .. consider the snippet just like an external php file, except that it has the benefit of being wrapped in the modx object model.
Many developers simply include or require an external php file from snippet code, so that you can use your debugger.
-
MODX Staff
- 730 Posts
If you’re doing a lot of ajax calls throughout your app, you might consider creating one resource to act as a controller for all of them. You’d just have to pass an additional identifier so that the controller knows what you’re calling.
That’s just one approach.
I know that the core developers also foresaw that developers would want to be able to create alternate front controllers so that, for example, your ajax requests don’t have to bottleneck through one resource. The Revolution manager itself issues ajax requests to ’connectors’ which are individual front controllers (the Wiki explains this much better than I can). My main point is that you are pretty free to handle this in a variety of ways.
Thank you, this really helps!
Ed