Welcome Guest, Not a member yet? Register   Sign In
Where i need to put the error performence, controller or model?
#1

[eluser]Asinox[/eluser]
Hi, i need to catch errors when the articles don't exist in database...but how ill do that?
where i need to put the performence?

thanks
#2

[eluser]Steve Grant[/eluser]
You could combine it within both the model and controller for extra safety.

For example, you have a function within a model that returns an array or object containing the article data, but returns null if it can't find an article that matches the ID provided.

Then within the controller, you can check the output to see if it's null. If it is null, output a suitable message or display an "error" view.

Model
Code:
function get_article($article_id)
{
  $query = $this->db->get_where('articles', array('article_id', $article_id));

  if($this->db->count_all_results() == 0)
  {
    return null;
  }
  else
  {
    return $query->row();
  }
}

Controller
Code:
function view()
{
  $data['article_data'] = $this->MyModel->get_article($this->uri->segment(3));

  if($data['article_data'] == null)
  {
    $this->load->view('error');
  }
  else
  {
    $this->load->view('article/view', $data);
  }
}

Something like that should do the trick.
#3

[eluser]Asinox[/eluser]
Thanks Steve

The perfect solution Big Grin




Theme © iAndrew 2016 - Forum software by © MyBB