Welcome Guest, Not a member yet? Register   Sign In
model in view, or passing from view strange behavior
#3

(10-25-2019, 12:29 PM)Wouter60 Wrote: Show us what my_function() function in your object looks like.
What type of object is it? CI uses objects (classes) in controllers, models and libraries.
You load a library in a controller with $this->load->library('library_name');
To call a function in the library: $var = $this->library_name->my_function($parameter);

Well I had to reimplement it because the original wasn't working, but it is pretty simple.

myfunction($db_object) {
   $returnValue = null;
   foreach($db_object as $db_row_value){
      if($db_row_key == $my_key)
         $returnValue = $db_row_value;
   }
   return $returnValue;
}

This is obviously not exactly, but this is the gist of it.


If I call this function from inside my view by passing in my model it has unexpected behavior. 

In the view I will loop over a $array_of_db_objects and then with the model $my_model->myfunction($db_object);

Instead of it being a single object it is the entire array I was looping over inside the view.

I hope this makes sense.
Reply


Messages In This Thread
RE: model in view, or passing from view strange behavior - by Goddard - 10-28-2019, 05:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB