Welcome Guest, Not a member yet? Register   Sign In
query big problem
#13

[eluser]xwero[/eluser]
I find it a bit strange you going to put the method in a model named comments. If you have a comments model you must have a news model so you should call news->by_id($news_id) and comments->for_news_id($news_id).

The idea about splitting up code is to make it simpler.

My method was written to belong to the news model. The controller method would look like this
Code:
function show($news_id = '')
{
    // no id no news item
    if($news_item == '')
    {
       redirect('news');  
    }
    
    $news_item = $this->news->by_id($news_item,true);
    // if there are no properties there is no news item
    if( ! isset($news_item->news_text) )
    {
       redirect('news');
    }

    $content = array();
    
    if(count($news_item->comments) > 0)
    {
        foreach($news_item->comments as $comment)
        {
            $content['comments'] .= $this->load->view('com/com_loop', $comment, true);
        }
    }
    // comments property is no longer needed
    unset($news_item->comments);
    
    $this->load->view('index', array_merge($content,(array)$news_item));
}


Messages In This Thread
query big problem - by El Forum - 04-24-2009, 03:45 AM
query big problem - by El Forum - 04-24-2009, 04:18 AM
query big problem - by El Forum - 04-24-2009, 04:22 AM
query big problem - by El Forum - 04-24-2009, 04:33 AM
query big problem - by El Forum - 04-24-2009, 04:34 AM
query big problem - by El Forum - 04-24-2009, 04:49 AM
query big problem - by El Forum - 04-24-2009, 04:54 AM
query big problem - by El Forum - 04-24-2009, 08:48 AM
query big problem - by El Forum - 04-24-2009, 11:57 AM
query big problem - by El Forum - 04-25-2009, 12:44 AM
query big problem - by El Forum - 04-25-2009, 02:32 AM
query big problem - by El Forum - 04-26-2009, 03:35 AM
query big problem - by El Forum - 04-26-2009, 04:53 AM
query big problem - by El Forum - 04-26-2009, 05:09 AM
query big problem - by El Forum - 04-27-2009, 12:46 AM
query big problem - by El Forum - 04-27-2009, 01:04 AM
query big problem - by El Forum - 04-27-2009, 05:54 AM
query big problem - by El Forum - 04-27-2009, 06:16 AM
query big problem - by El Forum - 04-27-2009, 01:04 PM
query big problem - by El Forum - 04-28-2009, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB