0

I'm using _remap:

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

I want to change the url http://localhost/blog to http://localhost/blog/hello

my CI_Controller is:

  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');
    }
}

How can I use this for any dynamic id and replace $row->subject with hello?

Wesley Murch
  • 101,186
  • 37
  • 194
  • 228
meti
  • 11
  • 3

1 Answers1

0

Instead of routing all passed methods to index, you could route it to another function and pass the method as the parameter to that function:

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;
 }
jpea
  • 3,114
  • 3
  • 26
  • 26