Welcome Guest, Not a member yet? Register   Sign In
I dunno. Help newbe with lib/models please
#1

[eluser]walrus_lt[/eluser]
Hello, i develop website. I am currently creating news/articles and i need your help people. How should i do.

Code:
class Articles_Lib
{
  function get_article($id)
  {
    // articles/article/1484
    if ( is_numeric($id) ){
      return $this->ci->articles_model->get_article_by_id($id);
    // articles/article/some-article-here
    } else {
      return $this->ci->articles_model->get_article_by_uid($id);
    }
  }
}

Vs.

Code:
class Articles_Lib
{
  function get_article($id)
  {
    return $this->ci->articles_model->get_article($id);
  }
}

class Articles_Model extends Model
{
  function get_article($id)
  {
    // articles/article/1484
    if ( is_numeric($id) ){
      return $this->db->query();
    // articles/article/some-article-here
    } else {
      return $this->db->query();
    }
  }
}

I dont want to brake MVC so please help. I would really aprecate your help people.
#2

[eluser]BenneX[/eluser]
As far as I understand, libs aren't part of the MVC. You could solve your problem with both of your solutions but I think it's better and easier to use your first example. In that case you only have to serve one file as a lib insted of blow it up with models etc. The only thing you should have to think about is multi-lang support, but thats also not really needed by a lib. Hope I could help you Wink

greetz

BenneX
#3

[eluser]walrus_lt[/eluser]
Hi. Thanks for reply. I decided to solve this in query, but use both lib's and then model Big Grin

Code:
function get_article($id)
  {
      return $this->db->select('id, uid, title, intro, time, views, comments')
                      ->order_by('id')
                      ->limit(10)
                      ->where('id', $id)
                      ->or_where('uid', $id)
                      ->get('articles');
  }
#4

[eluser]trice22[/eluser]
Could you explain what do you need the library for in this case?

Cheers,
—trice22




Theme © iAndrew 2016 - Forum software by © MyBB