Welcome Guest, Not a member yet? Register   Sign In
Replace underscore (_) with dashes (-) in URL
#9

[eluser]TheFuzzy0ne[/eluser]
I don't understand why either of the snippets you posted aren't working, other than the files the code was in weren't correctly named. Did you check to see if they were being called?

What if you wanted an underscore in the URL? I don't think the solution is to replace ALL hyphens with underscores. I think you should only do it where it's absolutely necessary, and that is for the directory, class and method properties. I'd go with something like this (untested):

./application/core/Router.php
Code:
class MY_Router extends CI_Router
{
    /**
    * Set the class name
    *
    * @access public
    * @param string
    * @return void
    */
    function set_class($class)
    {
        $this->class = str_replace(array('/', '.', '-'), array('', '', '_'), $class);
    }

    /**
    * Set the directory name
    *
    * @access public
    * @param string
    * @return void
    */
    function set_directory($dir)
    {
        $this->directory = str_replace(array('/', '.', '-'), array('', '', '_'), $dir).'/';
    }

    /**
    * Set the method name
    *
    * @access public
    * @param string
    * @return void
    */
    function set_method($method)
    {
        $this->method = str_replace('-', '_', $method);
    }
}

Now you can use underscores (if the need arises) in your URLs as well as hyphens.

Hope this helps. The actual GET array would remain unmodified, which may or may not be what you want. It should mean that the URI library will work exactly as expected.


Messages In This Thread
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-30-2013, 08:26 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-30-2013, 10:26 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-30-2013, 11:54 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-30-2013, 04:41 PM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 06:04 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 06:07 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 06:17 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 06:45 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 07:31 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 08:53 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 08:56 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 10:31 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 10:36 AM
Replace underscore (_) with dashes (-) in URL - by El Forum - 03-31-2013, 10:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB