Welcome Guest, Not a member yet? Register   Sign In
urls with dashes, instead of underscores
#14

[eluser]Jayson Ng[/eluser]
had problems with arguments not getting passed.

and since I wanted this on all my controllers, I put _remap into my MY_Controller.

Code:
// Remap dashes "-" in the URL to underscores "_"
    function _remap($method = NULL)
    {
        $size            = $this->uri->total_segments();
        $method_key        = array_search($method, $this->uri->segments);

        $method = str_replace('-','_',$method);
        if(method_exists($this, $method))
        {
            // is there a better way to pass methods? dynamically?
            // this only works with 5 arguments.
            $this->$method(
                      $this->uri->segment($method_key + 1)
                ,     $this->uri->segment($method_key + 2)
                ,     $this->uri->segment($method_key + 3)
                ,     $this->uri->segment($method_key + 4)
                ,     $this->uri->segment($method_key + 5)
                );
        }
        else
        {
            show_404();
        }
    }

and to solve the problem the arguments not passing, I did this.
crude but it works. I'm hoping for a more elegant solution if anybody has ideas.

This is a general function that will work (so far) for all controllers.


Messages In This Thread
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 04:18 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 04:21 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 04:22 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 04:27 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 05:08 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 05:10 PM
urls with dashes, instead of underscores - by El Forum - 07-11-2009, 06:02 PM
urls with dashes, instead of underscores - by El Forum - 07-12-2009, 12:11 AM
urls with dashes, instead of underscores - by El Forum - 07-12-2009, 01:37 AM
urls with dashes, instead of underscores - by El Forum - 07-12-2009, 06:04 AM
urls with dashes, instead of underscores - by El Forum - 07-16-2009, 10:27 AM
urls with dashes, instead of underscores - by El Forum - 09-14-2009, 11:52 PM
urls with dashes, instead of underscores - by El Forum - 09-16-2009, 10:22 AM
urls with dashes, instead of underscores - by El Forum - 09-17-2009, 06:06 PM
urls with dashes, instead of underscores - by El Forum - 09-17-2009, 06:57 PM
urls with dashes, instead of underscores - by El Forum - 09-17-2009, 06:59 PM
urls with dashes, instead of underscores - by El Forum - 09-17-2009, 09:10 PM
urls with dashes, instead of underscores - by El Forum - 09-18-2009, 12:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB