Welcome Guest, Not a member yet? Register   Sign In
Trying to overwrite a Router function don't work
#1

[eluser]CI Samson[/eluser]
I want to overwrite the function _filter_uri of the Router class to avoid the error message "The URI you submitted has disallowed characters.". So I have created a file MY_Router.php in the libraries folder of my application with the following code:

Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }
    
    function _filter_uri($str)
    {
        if ($this->config->item('permitted_uri_chars') != '')
        {
            if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
            {
                show_404();
                exit();
            }
        }    
        return $str;
    }
}

But it doesn't work, I see allays the same message.
Is it because the _filter_uri function is called in the constructor of the Router class ?
How can I do to show a not found page at the place of the error message without changing the core router class ?

Thank you for your help!
#2

[eluser]Pascal Kriete[/eluser]
Never mind, I can't read.
#3

[eluser]CI Samson[/eluser]
[quote author="inparo" date="1201989708"]Never mind, I can't read.[/quote]

Well... may I help you ?
#4

[eluser]BoltClock[/eluser]
You made a little mistake there. The _filter_uri() method is found in the URI class, not the Router class, so you should extend that instead Smile

Let me know if it works after you make the change.
#5

[eluser]CI Samson[/eluser]
Thank you BoltClock, now it works!




Theme © iAndrew 2016 - Forum software by © MyBB