2011-06-10 2 views
0

J'utilise _remap:Utilisation de _remap avec des segments d'URL dynamiques

function _remap($method) 
    { 
     // $method contains the second segment of your URI 
     switch($method) 
     { 
      case 'hello': 
       $this->index(); 
       break; 
     } 
    } 

Je veux changer l'URL http://localhost/blog-http://localhost/blog/hello

mon CI_Controller est:

class Blog extends CI_Controller { 
    function __construct() 
    { 
     parent::__construct();     
    } 

    function _remap($method) 
     { 
      // $method contains the second segment of your URI 
      switch($method) 
      { 
       case 'hello': 
        $this->index(); 
        break; 
      } 
     } 
    /**/ 
    function index() 
    { 

       $g_subject = $this->input->get('id', TRUE);   
       $query = $this->db->get_where('miniblog', array('id' => $g_subject)); 
       foreach ($query->result() as $row) 
       { 
       $data = array(
        'subject' => $row->subject, 
        'title' => $row->title,     
        'image_path' => $row->image_path, 
        'alt' => $row->alt, 
        'text' => $row->text, 
        'date' => $row->date, 
       ); 
       } 

       $this->load->view('miniblog/blog', $data); 
       //add customer size to databe on customer 

       //$this->customer_size_model->show(); 

    } 
    function ipv6() 
    { 
     $this->load->view('miniblog/ipv6'); 
    } 
} 

Comment puis-je utiliser cela pour tout id dynamique et remplacer $row->subject avec bonjour?

Répondre

0

au lieu d'acheminer toutes les méthodes transmises à l'index, vous pouvez acheminer à une autre fonction et de transmettre la méthode comme paramètre à cette fonction:

function _remap($method){ 
     // $method contains the second segment of your URI 
     switch($method){ 
      case 'index': 
       $this->index(); 
       break; 
      default: 
       $this->all_encompasing_method($method); 
     } 
} 

function all_encompasing_method($url_param){ 
     // here's my param 
     echo $url_param; 
} 
Questions connexes