Ms. A
Ms. A

Reputation: 45

Codeigniter / Ionic - How to solve "Object of class stdClass could not be converted to string"?

I have this code for getting data from web to my ionic but i keep on getting the error "Object of class stdClass could not be converted to string". What should I do with this?

enter image description here

model(codeigniter):

public function getRecipeDetails($id){
$this->db->select('*');
$this->db->from('recipe');
$this->db->where('recipe_id',$id);
$query = $this->db->get();
return $query->row();   
 }

controller (codeigniter):

public function recipeDetails(){

    $postdata = json_decode(file_get_contents("php://input"));
    var_dump($postdata->recipeId);
    $msg = $this->user_model->getRecipeDetails($postdata->recipeId);
    echo json_encode($msg);

}

Service (ionic)

.factory('RecipeList', function( $http, $stateParams){
    var returnSearchData = {};
    var recipeDetail = {};

return {
    getSingleFuckinRecipe : function(){
        return recipeDetail;
    },
    getRecipeDetails : function(id){
        if(id) {
            console.log(id);
            var recipeData = {
                recipeId : id
            }
            $http(
                    {
                        method: 'POST',
                        header: {'Content-Type' : 'application/x-www-form-urlencoded'},
                        url: 'http://localhost/admin-recipick/home/recipeDetails',
                        data: recipeData
                    }
                )
                .then(
                    function success( response ) {
                        recipeDetail = response.data;
                        console.log(response.data);
                    },
                    function error( response ) {
                        recipeDetail = response.data;
                        console.log(response.data);
                        // handle error
                    }

                );
        }
        else {
        }
    }
  })

controller (ionic)

$scope.getDetails = function(id){
   // console.log(r_Id);

    var RecipeId ={
      recipeId : id
    }
    RecipeList.getRecipeDetails(RecipeId);
}

view (ionic)

  <div class="list card" ng-repeat="search in search |  filter:cookingtime:search.r_time">

 <div class="item item-icon-right b">
     <h1>{{search.r_name}}</h1>
 </div>

 <div class="item item-image">
    <img src="img/food/porkmenudo.jpg">
 </div>
 <div class="item assertive" >   
    <rating ng-model="rate" max="max" readOnly="true"></rating>

    <i class="ri icon ion-chevron-right"  ng-click="getDetails('{{search.recipe_id}}')"></i>

 </div>

Upvotes: 1

Views: 229

Answers (2)

Ms. A
Ms. A

Reputation: 45

I've found the answer you just have to change controller(ionic):

$scope.getDetails = function(id){

var RecipeId ={
  recipeId : id
}
RecipeList.getRecipeDetails(RecipeId);

}

into controller (ionic)

 $scope.getDetails = function(id){
    RecipeList.getRecipeDetails(id); 
}

Upvotes: 0

safin chacko
safin chacko

Reputation: 1390

try in model

return $query->row();  
with
 return $query->result();  
or
return $query->result_array(); 

Upvotes: 0

Related Questions