Welcome Guest, Not a member yet? Register   Sign In
Datamapper best practice
#1

[eluser]davidMC1982[/eluser]
I have the following code in my controller:

Code:
class Products extends CI_Controller {

public function list_products($manufacturer_id = null) {
  if($manufacturer_id) {
  
   $products = new Product();
   $data['products'] = $products->where('manufacturer_id', $manufacturer_id)->get();
  }
  else {
  
   $products = new Product();  
   $data['products'] = $product->get();
  }
      
   $this->load->view('templates/header');
   $this->load->view('list_products', $data);
   $this->load->view('templates/footer');
}
}

And the following in my model:

Code:
class Product extends Datamapper {

var $has_one = array("manufacturer");
var $has_many = array("orderdetail, item, rate");

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }


}

Obviously, the code is intended to list all the products in the database, by manufacturer if given and pass these objects to the view.

Best practice suggests fat models and thin controllers. However, when using an ORM such as Datamapper the "fat model" part seems to be mostly taken care of automagically. My question is, in this case, how should the code above be altered?


Messages In This Thread
Datamapper best practice - by El Forum - 11-09-2012, 02:46 PM
Datamapper best practice - by El Forum - 11-09-2012, 03:00 PM
Datamapper best practice - by El Forum - 11-15-2012, 06:23 AM
Datamapper best practice - by El Forum - 11-16-2012, 01:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB