Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codeigniter 使用动态URL段的_重新映射_Codeigniter_Remap - Fatal编程技术网

Codeigniter 使用动态URL段的_重新映射

Codeigniter 使用动态URL段的_重新映射,codeigniter,remap,Codeigniter,Remap,我正在使用_remap: function _remap( $method ) { // $method contains the second segment of your URI switch( $method ) { case 'hello': $this->index(); break; } } 我想更改urlh

我正在使用_remap:

function _remap( $method )
    {
        // $method contains the second segment of your URI
        switch( $method )
        {
            case 'hello':
                $this->index();
                break;
        }
    }
我想更改urlhttp://localhost/blog 到http://localhost/blog/hello

我的CI_控制器是:

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

如何将其用于任何动态id并用hello替换$row->subject?

而不是将所有传递的方法路由到index,您可以将其路由到另一个函数,并将该方法作为参数传递给该函数:

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