public function forSelection() { $term = $this->input->get('q', null, 'default'); $key = new \MongoRegex('/' . $term . '/i'); $results = \Shop\Models\Coupons::forSelection(array('title' => $key)); $response = new \stdClass(); $response->more = false; $response->term = $term; $response->results = $results; return $this->outputJson($response); }
data: function (term, page) { return { q: term }; }, results: function (data, page) { return {results: data.results}; } } <?php if ($flash->old('required_coupons')) { ?> , initSelection : function (element, callback) { var data = <?php echo json_encode(\Shop\Models\Coupons::forSelection(array('_id' => array('$in' => array_map(function ($input) { return new \MongoId($input); }, (array) $flash->old('required_coupons')))))); ?> ; callback(data); } <?php } ?> }); jQuery("#required_collections").select2({ allowClear: true, placeholder: "Search...", multiple: true, minimumInputLength: 3,