Welcome Guest, Not a member yet? Register   Sign In
Calling Model From View File?

Here's something I quickly put together which should do the trick
The key is the join in the model, which joins the user and comments table together

function get_comments($story_id) {
    $this->db->where('story_id', $story_id);
    $this->db->join('users', 'userd.id = comments.user_id');
    return $this->db->get('comments');

function view_story($id) {
    $data['story'] = $this->story->get_story($id);
    $data['comments'] = $this->comment_model->get_comments($id);
    $this->load->view('story_with_comments', $data);

echo $story->title;
echo $story->body;
foreach($comments as $comment) {
    echo $comment->title;
    echo $comment->user_name;
    echo $comment->body;

Let me know if this is the sort of thing you're after, and if it works (not tested)

Cool cool thanks Dam1an i was just looking at joins also i was thinking that was the way to go ..

Thanks again.

Problem Solved

Your welcome
And once you start using joins, you wonder how you ever lived without them

I came accross some of my old PHP code, and I had loads of calls just like yours was before (although mine was even worse as this was pre MVC, so all my SQL was in the views)

Yea that's how mine are also in previous code lol...

[eluser]Thorpe Obazee[/eluser]
@OP. Actually, Bamboo Invoice does use model calls from the view. Although, I'd prefer helpers getting the info.

Theme © iAndrew 2016 - Forum software by © MyBB