i have search query in codeigniter problem dont know how implement in ionic. want if search on searchbox in ionic(home.html) ex. "pepper, oil" , result should recipe corresponds ingredients adobo , kaldereta.
user_model.php ( codeigniter - model )
public function get_halal($search_values) { $this->db->distinct(); $this->db->select('*'); $this->db->from('recipe'); $this->db->join('menu', 'menu.recipe_id = recipe.recipe_id'); $this->db->join('ingredient', 'ingredient.ingredient_id = menu.ingredient_id'); $this->db->where('menu.category_id = 1'); if (strpos($search_values, ',') !== false) { $search = explode(',' , $search_values); $this->db->like('ingredient.name', trim($search[0]), 'both'); unset($search[0]); foreach ($search $term) { $this->db->or_like('ingredient.name', trim($term), 'both'); } } else { //this means have 1 value $this->db->like('ingredient.name',$search_values, 'both'); } $query = $this->db->get(); return $query->result(); }
home.php ( codeigniter - controller )
public function ajaxsearchhalal() { $postdata = file_get_contents("php://input"); if (isset($postdata)) { $data = $this->user_model->get_halal($postdata); echo json_encode($data); } }
searchservice.js ( ionic )
return { all: function() { return $http.get('http://localhost/admin-recipick/home/ajaxsearchhalal').then(function(result){ return result.data; console.log(result.data); }); } }
controller.js (ionic)
recipelist.all().then(function(payload) { $scope.recipedata = payload; console.log(payload); }); $scope.searcrecipe = function() { recipelist.all(); $state.go('app.searchrecipe'); };
home.html ( ionic - view )
<div class="list list-inset"> <label class="item item-input"> <i class="icon ion-search placeholder-icon"></i> <input type="text" ng-model="" placeholder="(ex. beef, fish, corn)"> </label> <button type="button" class="button button-block button-assertive icon ion-search " ng-click="searcrecipe()"> search</button> </div>
recipelist.all().then(function(payload) { console.log(payload.data); });
use payload.data getting response.
Comments
Post a Comment