[SOLVED] call MODEL functions in the VIEW, really bad idea?

[quote author="Maglok" date="1250164447"]I'd probably go with making a big query and putting it in my model. You could still move all the small bits to the controller though.

If you simply get a set:
$data['personen'] = $this->model_persoon->get_all();

Or you need to process it first before sending it to the view like this:
foreach($query->result() as $row) {
                    $karakter_options[$row->id] = $row->naam;

Regardless, you can access them in the view when gotten from the model in the Controller.[/quote]
yeah, why I didn't think about that.
thank you

[quote author="waldmeister" date="1250166908"]Why not do it all in the model?
//in your controller
function show_product_list()
  $data = array();
  $data['product_list'] = $this->Model_name->get_product_list()
  $this->load->view('my_view_name', $data);
//in your model
function get_product_list()
  $query = $this->db->get('product');
  $return = array();
  foreach($query->result_array() as $key => $product)
    $return[$key] = $product;
    $return[$key]['num_image'] = $this->get_num_image($product['id']);
    $return[$key]['num_video'] = $this->get_num_video($product['id']);
    // and so on
  return $return;

//in your view
print_r($product_list); // or whatever you want to do
looks very promising. I am gonna try it now.

I have re-coded my view and model as waldmeister suggested, it works great.
thanks guys for helping me Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.