Welcome Guest, Not a member yet? Register   Sign In
How i can use model in other model?
#3

[eluser]Craig A Rodway[/eluser]
Load the CI instance into a variable, and load/access other models through it, like this:

Code:
<?php
class Posts extends Model {

  var $CI;

  function Posts() {
    parent::Model();
    // Assign CI instance to variable so it is available to all functions in this model
    $this->CI =& get_instance();
  }


  function getPostOrderId($id) {
    $result = dibi::fetchAll('SELECT * FROM posts JOIN users ON posts.user_id=users.user_id where POST_ID =%i',$id);
        
    // Load comments model from CI instance
    $this->CI->load->model('comments');
    // Call function in the comments model using the CI instance
    $comments = $this->CI->comments->getCommentsForPost($id);

    var_dump($comments);
    return $result;        
    }

}
?>


Messages In This Thread
How i can use model in other model? - by El Forum - 12-30-2007, 06:09 AM
How i can use model in other model? - by El Forum - 12-30-2007, 07:32 AM
How i can use model in other model? - by El Forum - 12-30-2007, 07:39 AM
How i can use model in other model? - by El Forum - 12-30-2007, 07:46 AM
How i can use model in other model? - by El Forum - 12-30-2007, 07:55 AM
How i can use model in other model? - by El Forum - 01-05-2008, 01:02 PM
How i can use model in other model? - by El Forum - 01-05-2008, 01:08 PM
How i can use model in other model? - by El Forum - 01-05-2008, 01:19 PM
How i can use model in other model? - by El Forum - 01-05-2008, 01:34 PM
How i can use model in other model? - by El Forum - 01-05-2008, 01:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB