Welcome Guest, Not a member yet? Register   Sign In
How to write models
#5

[eluser]papagno[/eluser]
I'll use an example. We have two entities: posts and comments (each post can have many comments). This could be a basic posts model:
Code:
class Post extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }
    
    function get_posts()
    {
        $query = $this->db->get('posts');
        return $query->result();
    }

Now in the posts controller I can use:
Code:
$this->load->model('post');
$posts = $this->post->get_posts();

But $posts is not an array of objects, it's just a multidimensional array. So I don't know how (and where) to add a method to fetch comments for a post.

p.s. I'm sorry for my English Smile


Messages In This Thread
How to write models - by El Forum - 02-11-2011, 10:08 AM
How to write models - by El Forum - 02-11-2011, 10:20 AM
How to write models - by El Forum - 02-11-2011, 10:22 AM
How to write models - by El Forum - 02-11-2011, 10:23 AM
How to write models - by El Forum - 02-11-2011, 10:44 AM
How to write models - by El Forum - 02-11-2011, 10:50 AM
How to write models - by El Forum - 02-11-2011, 11:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB