Welcome Guest, Not a member yet? Register   Sign In
Controller with Infinite Arguments($a,$b,$c,$d...), i.e. a Catch-all Solution
#1

[eluser]fireproofsocks[/eluser]
I know there are some libraries that do this, but I just needed this for a single controller... the situation is that a controller needed to handle some encypted data to validate an account. It worked fine until the encrypted data got forward slashes in it occasionally... and it was a variable number of them.

Like a lot of hacks (e.g. to gain access to $_GET variables), this involves the $_SERVER variable. The goal was to have urls like:
http://yoursite.com/x/y/1/2/3/4/5
and a controller that could have a single variable containing '1/2/3/4/5'

Code:
class X {
// [...]
    function y($z)
    {
      // $z is thrown away
        $this_controller = '/x/y/';
        $all_incoming_data = preg_replace('#^'.$this_controller.'#','',$_SERVER['REDIRECT_URL'] );
        // http://yoursite.com/x/y/1/2/3 will result in $all_incoming_data containing '1/2/3'
        print $all_incoming_data;
    }
}

This solution may not be 100% reliable, and it may not work on every server, so I suggest using it with caution.
#2

[eluser]Michael Wales[/eluser]
I would just use URI Routing to catch everything and pass it as one variable to the method...
#3

[eluser]danmontgomery[/eluser]
http://php.net/manual/en/function.func-get-args.php
#4

[eluser]fireproofsocks[/eluser]
I tried using routing, both the normal routes and the regular expression routes, but I wasn't able to make this work e.g.

Code:
$route['x/y/(.*)'] = 'x/y/$1';

func_get_args() -- I didn't think of that... that function is not in my active vocabulary so it didn't leap to mind, but it's a simpler solution.




Theme © iAndrew 2016 - Forum software by © MyBB