public function forSelection() { $term = $this->input->get('q', null, 'default'); $key = new \MongoRegex('/' . $term . '/i'); $results = \Shop\Models\Collections::forSelection(array('title' => $key)); $response = new \stdClass(); $response->more = false; $response->term = $term; $response->results = $results; return $this->outputJson($response); }
minimumInputLength: 3, ajax: { url: "./admin/shop/collections/forSelection", dataType: 'json', data: function (term, page) { return { q: term }; }, results: function (data, page) { return {results: data.results}; } } <?php if ($flash->old('discount_target_collections')) { ?> , initSelection : function (element, callback) { var data = <?php echo json_encode(\Shop\Models\Collections::forSelection(array('_id' => array('$in' => array_map(function ($input) { return new \MongoId($input); }, (array) $flash->old('discount_target_collections')))))); ?> ; callback(data); } <?php } ?> }); }); </script>