1

I am new to MVC and trying to continue to learn base on best practices. I am trying to return data from multiple sources -- one source being a mysql db query and another source from another method that will pull data from facebook.

Here is what I have so far:

Model:

function get_users() {
  $this->db->select('id');
  $this->db->from('users');
  $query = $this->db->get();
  return $query->results;
}
function attach_cover($user_list) {
  foreach($user_list as $user){
    $user->cover = get_cover_value($user->id);
  }
  return $user_list;
}

controller:

$this->load->model('user_model', '', TRUE);
$data['users'] = $this->user_model->get_users();
$data['user_cover'] = $this->user_model->attach_cover($data['users']);
$this->load->view('index', $data);

view:

foreach($data as $item) {
  echo $item->id;
  echo $item->cover;
}

Question:

Is this the right approach to do so? Or is there a better method? The framework I am currenty using is Codeigniter.

Hope to learn.

Rick

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.