Forked from rakeshtembhurne/cakephp_get_list_data_in_json.php
Created
January 7, 2014 11:14
-
-
Save narendrakamadi/8297942 to your computer and use it in GitHub Desktop.
Revisions
-
rakeshtembhurne created this gist
Jan 3, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ <?php /** * Gets list from various models * * @param string $modelName Model name * @param string $key field name used in condition * @param string $value value of field used in conditions * * @return json */ public function get_list($modelName, $key = null, $value = null) { $this->autoLayout = false; $this->autoRender = false; $options = array('is_active' => 1); if (!empty($key) && !empty($value)) $options['conditions'] = array("{$modelName}.{$key}" => $value); $data = ClassRegistry::init($modelName)->find('list', $options); echo json_encode($data); }//edn get_list() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ $("form").on("change", "#UserSiteId", function(event) { var siteId = $(this).val(); // Call CakePHP get_list function here $.post(window.app.baseUrl + "users/get_list/Wing/site_id/" + siteId, function(response) { var data = JSON.parse(response); // Empty initially var wingOptions = ""; $userWingId.html(""); // Inject data for (var key in data) { wingOptions += "<option value=" + key + ">" + data[key] + "</option>"; }; $userWingId.html(wingOptions); $userWingId.trigger("change"); }); }); $("#UserSiteId").trigger("change");