Added Intro to AJAX for these plugins
authorChuck Scott <cscott@gaslightmedia.com>
Wed, 30 Mar 2016 17:25:33 +0000 (13:25 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Wed, 30 Mar 2016 17:25:33 +0000 (13:25 -0400)
models/admin/ajax/readme.txt [new file with mode: 0644]

diff --git a/models/admin/ajax/readme.txt b/models/admin/ajax/readme.txt
new file mode 100644 (file)
index 0000000..07c37ec
--- /dev/null
@@ -0,0 +1,40 @@
+Intro to AJAX for these plugins
+-------------------------------
+
+WordPress has an AJAX capability that works through "wp-admin/admin-ajax.php". You can use this
+to support AJAX calls, but also can use it to do direct output to the user's browser without
+outputting any of the other front-end or admin wordpress content.
+
+This is driven in these plugins by an add_action() call in the admin controller (controllers/admin.php).
+That routes all calls for the following url base to the glmMembersAdminAjax() function in the admin 
+controller. Note that action and other parameters may be supplied by GET or POST.
+
+ {host}/wp-admin/admin-ajax.php?action=glm_members_admin_ajax
+ The glmMembersAdminAjax() function then looks for a "glm_action" parameter that specifies the name
+ of a model file to load and execute. This model MUST be in a "models/admin/ajax" directory in the
+ main plugin or one of the add-ons and MUST be listed in the "setup/validActions.php" file of that
+ plugin or add-on. Here is an example of setting the valid action for an ajax model. Obviously there
+ would be other valid actions listed.
+ $glmMembersEventsAddOnValidActions = array(
+    'adminActions' => array(
+        'ajax' => array(
+                'pdfOutput' => 'glm-member-db'
+        )
+    )
+);
+
+The model file loaded will be named by the "glm_action" parameter plus ".php". The admin controller
+will load the class in the model named as follows where "pdfOutput" is the value provided by the
+"glm_action" parameter. It will then call the modelAction() function in that class.
+
+class GlmMembersAdmin_ajax_pdfOutput
+
+You may include all your code in the called model file or may extend another model to produce your 
+output. Output may include custom headers and any desired content. The controller will execute a
+wp_die() function call to terminate any further processing if there is a return from the model's
+modelAction() function. This prevents any additional output from reaching the browser.
+
+
\ No newline at end of file