Welcome Guest, Not a member yet? Register   Sign In
Trouble populating form with data from database
#2

ProductsEdit_Controller->get() calls $this->products_Model->get($id), but the get() method in products_Model doesn't return anything. What you want to return from the method when data is not found is largely up to you, but I would generally do something like this:

PHP Code:
   public function get($id)
 
   {
 
       $query $this->db->get_where('products', array('id' => $id));
 
       if ($query->num_rows() > 0) {
            return 
$query->row_array();
        }

        
// No data found.
        
return null;
 
   

The calls to echo in the model may allow you to see the data returned from the database query, but performing an echo from a model will usually break the layout of the page because it causes your application to start output before your views are loaded.


If you need to see the data in your model and can't wait until it's passed back to your controller and through to your view, then you should setup a debugger.
Reply


Messages In This Thread
RE: Trouble populating form with data from database - by mwhitney - 05-27-2015, 08:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB