How to pass parameters in index function in codeigniter

后端 未结 12 1885
傲寒
傲寒 2020-12-14 03:02

here\'s an example of url: http://www.example.com/search/search-keyword

I am trying to make this work, I removed the index.php using .htaccess, search is the contro

12条回答
  •  庸人自扰
    2020-12-14 03:39

    This is my solution:

    From CI userGuide

    public function _remap($method)
    {
        if ($method == 'some_method')
        {
            $this->$method();
        }
        else
        {
           $this->default_method();
        }
    }
    

    So I've created my controller in this way:

    class Shortener extends CI_Controller {
    function shortener() {
        parent::__construct();
    }
    
    function index($getVar) {
        echo "Get var: " . $getVar;
    }
    
    function config() {
        echo "another function";
    }
    
    function _remap($method) {
        if($method == "config") {
            $this->$method();
        }
        else {
    
            $this->index($method);
        }
    }
    }
    

    Hope this can be helpful to someone...

    BUG: if you call /shortener _remap function pass "index" to index() function...it can be solved adding an if condition or something else

提交回复
热议问题