0

我正在使用_remap:

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

我想将网址更改http://localhost/bloghttp://localhost/blog/hello

我的 CI_Controller 是:

  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 并替换$row->subject为 hello?

4

1 回答 1

0

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

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;
 }
于 2011-06-11T14:47:30.113 回答