Welcome Guest, Not a member yet? Register   Sign In
Is it standard practice to do this
#1

[eluser]Unknown[/eluser]
So two questions. First of all here is my code ... (it's missing error checking atm).

Code:
class Covers extends CI_Controller {

public function index() {
  
}

public function category($slug) {
  $this->load->model('Cover', 'cover', TRUE);
  
  if($covers = $this->cover->get_covers_by_category($slug)) {
  
   $tmpCovers = array();
  
   foreach($covers as $cover) {
    $tmpCovers[]['cover'] = $cover;
    $tmpCovers[]['tags'] = $this->cover->get_tags($cover['cover_id']);
   }
  
   $data['title'] = $covers[0]['name'];
   $data['covers'] = $tmpCovers;
  
   $this->load->view('category', $data);
  } else {
   show_404();
  }
}

public function single($slug) {
  $this->load->model('Cover', 'cover', TRUE);
  
  if($cover = $this->cover->get_cover($slug)) {
   var_dump($cover);
  } else {
   show_404();
  }
}

}

The first question is about the the way that I'm adding tags to each cover/article. I'm looping through each cover/article, then doing another database request to get the tags for that cover/article and appending it to a new array. Is it ok to do that or should that be done in the model?

The second question is single() method. I feel as if I should be creating a separate controller for returning single covers as the current class is plural and that method only returns a single result. Should I create a separate model and control for returning single covers/articles?

I have routing that routes:

covers/single/slug.html => slug.html

and

covers/category/slug => category/slug

I'm new to using a framework and would rather learn the correct practices and coding conventions.

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB