Welcome Guest, Not a member yet? Register   Sign In
Get news by id.. help
#1

[eluser]Evollution[/eluser]
i have a function that should get news contenct by id but i don't understand what it don't works so

controller/news.php
(i wanna acces news by this url : site.com/news/news-id/news-title/
Code:
public function _remap($method)
  {
     if(method_exists($this,$method))
     {
       $this->$method();
     }
     elseif(is_numeric($method) && $method > 0)
     {
       $this->_show_article();
     }
     else
     {
       $this->index();
     }
  }
private function _show_article()
  {
     $article_id=(int)$this->uri->segment(2);
     $this->load->model('news_model');
if(!$data=$this->news_model->get_article_by_id($article_id))
{
   redirect('news');
}
else
  {
   echo $news_content;
}
  }


/models/news-model.php

Code:
function get_article_by_id($article_id)
    {
                $this->db->select('title,news');
                $this->db->from('news');                
                $this->db->where('id', $article_id);
                 $query = $this->db->get();


        return ;
    }

now when i acces site.com/news/news-id .. i am redirected to news index


direct link (http://www.fifago.com/demo2/index.php/news)
#2

[eluser]Cristian Gilè[/eluser]
Hi Evollution, your model doesn't return anything!

Cristian Gilè
#3

[eluser]InsiteFX[/eluser]
/models/news-model.php
Code:
function get_article_by_id($article_id)
{
    $data = array();
    
    $this->db->select('title,news');
    $this->db->from('news');
    $this->db->where('id', $article_id);
    $query = $this->db->get();

    if ($query->num_rows() > 0)
    {
        $data = $query->row_array();
    }

    $query->free_result();

    return $data;
}

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB