Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

php - handling get urls in codeigniter

I am trying to create a message that shows up when login.php?e=1 on the login page: /login/. The issue I am coming to have is that in codeigniter when I do /login/e/1/ codeigniter seems to think e is a function and thus, since it doesnt exist, outputs a 404. I am trying, in the index function to grab the segments like a get request, however this does not work. How can one do typical get requests that would be trivial outside of codeigniter, in codeigniter while staying true to the uri that codeigniter uses?

    // Are they attempting to access a secure page?
    if ($this->uri->segment(1) == 'e' && $this->uri->segment(2) == '1'):
        if ($this->generic->getOption('block-msg-out-enable')) {
            $this->msg = $this->generic->getOption('block-msg-out');
        }
    endif;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

there is nothing to show just hit this link.

If you are lazy then watch it here.

_remap function overrides index() (or any other declared function in a controller), in a way

function _remap($method, $params) {

    if (method_exists($this, $method)) {

        return call_user_func_array(array($this, $method), $params);

    } else {

        array_unshift($params, $method);
        return call_user_func_array(array($this, "index"), $params);

    }

}

//after 1st comment take a look here

function _remap($method, $params) { //this is "kind" of your new index(); but it takes parameters

    if ($method == 'e') {

        echo $params[0];

    } else {

        show_404();

    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...