HELP with URL

#1
[eluser]Evollution[/eluser]
http://www.fifago.com/demo2/index.php/news

so i created news ...

what shoud i do so that when i acces :

http://www.fifago.com/demo2/index.php/news/3
http://www.fifago.com/demo2/index.php/news/4 ...

see the news content with id 4 ..

txn

#2
[eluser]Twisted1919[/eluser]
Simple:
Code:
class News extends Controller{

  public function __construct()
  {
    parent::Controller();
  }  

  public function _remap($method)
  {
     if(method_exists($this,$method))
     {
       $this->$method();
     }
     elseif(is_numeric($method) && $method > 0)
     {
       $this->_show_article();
     }
     else
     {
       $this->index();
     }
  }

  public function index()
  {
      //here you extract the data for pagination, the url will be like:
      // index.php/news/index/10
  }

  private function _show_article()
  {
     $article_id=(int)$this->uri->segment(2);
     if(!$data=$this->MODEL->GET_ARTICLE_BY_ID($article_id))
     {
         redirect('news');
     }
     //valid areticle, show it .
  }


}

P.S: esti roman din cate vad, nu? Smile

#3
[eluser]Evollution[/eluser]
da Smile mersi

#4
[eluser]Evollution[/eluser]
Fatal error: Call to a member function GET_ARTICLE_BY_ID() on a non-object in /home/fifagoc1/public_html/demo2/application/controllers/news.php on line 52


poate trebuie sa fac load la vreo librarie ?

#5
[eluser]Evollution[/eluser]
+ e posibil de facut putin seo adica daca o sa pun

/id/news-title .. nu vor fi probleme cu functia asta !?

#6
[eluser]Evollution[/eluser]
MY code
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class News extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->model('news_model');
        
    }
public function _remap($method)
  {
     if(method_exists($this,$method))
     {
       $this->$method();
     }
     elseif(is_numeric($method) && $method > 0)
     {
       $this->_show_article();
     }
     else
     {
       $this->index();
     }
  }

     //paginarea ..
    
    function index()
    {
        $data = array();
    
        $this->load->library('pagination');
        $config['base_url'] = 'http://www.fifago.com/demo2/index.php/news/index';
        $config['total_rows'] = $this->db->get('news')->num_rows();
        $config['per_page'] = 10;
        $config['num_links'] = 20;

        $this->pagination->initialize($config);

        $this->load->helper('form');    

            if($query = $this->news_model->get_last_ten_entries())
    {
            $data['records'] = $query;
    }    
            $this->load->view('news_view', $data);    


    }

     // noutatile in functie de id

  private function _show_article()
  {
     $article_id=(int)$this->uri->segment(2);
     if(!$data=$this->MODEL->GET_ARTICLE_BY_ID($article_id))
     {
         redirect('news');
     }
  }

#7
[eluser]Evollution[/eluser]
din cate am inteles eu trebuie sa fac functia GET_ARTICLE_BY .. in model

si am facut ceva de genu
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 ;
    }

.. poate incurc eu ceva :\

#8
[eluser]Twisted1919[/eluser]
Daca modelul tau se numeste News_model si metoda din model care ia stirile se numeste get_article_by_id($article_id) atunci:
Code:
$this->load->model('news_model');
if(!$data=$this->news_model->get_article_by_id($article_id))
{
   redirect('news');
}
Apuca-te si citeste documentatia cum trebuie ca n-ai sa reusesti altfel .

#9
[eluser]Evollution[/eluser]
da acum merge doar ca cand apas pe url autopat face redirect la /news

http://www.fifago.com/demo2/index.php/news/3


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.