CodeIgniter Forums
Trying to overwrite a Router function don't work - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Trying to overwrite a Router function don't work (/showthread.php?tid=5736)



Trying to overwrite a Router function don't work - El Forum - 02-02-2008

[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!


Trying to overwrite a Router function don't work - El Forum - 02-02-2008

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


Trying to overwrite a Router function don't work - El Forum - 02-03-2008

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

Well... may I help you ?


Trying to overwrite a Router function don't work - El Forum - 02-03-2008

[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.


Trying to overwrite a Router function don't work - El Forum - 02-03-2008

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