Welcome Guest, Not a member yet? Register   Sign In
Controller Parameters should display 404 if reached maximum allowed params
#1

[eluser]drewbee[/eluser]
Lets say we have an example controller foo with a method bar that takes 0 parameters. Function shimmy can take up to two parameters

Code:
controller Foo extends Controller
{
    function index()
    {
        echo 'index page';
    }

    function bar()
    {
        echo 'woot';
    }

    function shimmy($param1 = '', $param2 = '')
    {
        echo 'Param1: ' . $param1 . ' Param2: ' . $param2;
    }
}

Here is what happens when accessing each url (this is expected and works correctly):

[200] /foo > index page
[200] /foo/bar > woot
[404] /foo/asdf
[404] /foo/bar/asdf

However, if a method can take parameters, it allows unlimited entries in the url, even if only the first are actually passed:

[200] /foo/shimmy > Param1 Param2
[200] /foo/shimmy/asdf > Param1 asdf Param2
[200] /foo/shimmy/asdf/jkl > Param1 asdf Param2 jkl
[200] /foo/shimmy/asdf/jkl/a/b/c/d/e/f/g > Param1 asdf Param2 jkl

^ I would expect the last one to throw a 404. Anything over two should throw the 404.

Thoughts, comments? I happened to run across this because I build my bread crumbs dynamically based on the directory path.
#2

[eluser]Derek Allard[/eluser]
url segments are automatically passed, but that doesn't mean the function is limited to ONLY 2. You've done a great breakdown here, but I don't feel this is a bug.
#3

[eluser]drewbee[/eluser]
Correct. I was thinking that the amount of segments should be limited by the number of parameters in the controller method.

It just caught me by surprise when I was building my auto breadcrumbs and all of a sudden they were extended out to the /a/b/c/d/e/f/g part of it.
#4

[eluser]simshaun[/eluser]
While limiting the URI to the number of parameters in the method might be needed in certain situations, the current behavior is needed in others... Some people may use func_get_args.

I think it would be ideal if you could specify in the config whether to limit the URI to the number of parameters in the method.
#5

[eluser]drewbee[/eluser]
If this were a configuration option, I would rather see it specified as an option to 'only pass the number of parameters', rather then limiting it. Some methods may accept up to x parameters from the uri, while others require none. A solid number in a configuration wouldn't be an ideal way of going about it.
#6

[eluser]simshaun[/eluser]
I think you may have mis-understood my post.
I was not suggesting limiting to X number of parameters in the config.
I was suggesting limiting to the number of parameters that a method has.
Its a simple TRUE/FALSE config option.
#7

[eluser]Derek Allard[/eluser]
If either of you want to start by writing an extended lib that is backwards compatible and includes simple config options, then get it tested on PHP 4 and 5, and then get it tested by members of the community I'd be open to taking a look.
#8

[eluser]drewbee[/eluser]
Sorry Sim... I am all over the place this mourning... just one of those days! Smile

This will definitely be something I will be extending on my own site... so let me take a look and see what I can do...
#9

[eluser]simshaun[/eluser]
[quote author="Derek Allard" date="1235511226"]If either of you want to start by writing an extended lib that is backwards compatible and includes simple config options, then get it tested on PHP 4 and 5, and then get it tested by members of the community I'd be open to taking a look.[/quote]

Added to my continually expanding to-do list. Wink
#10

[eluser]drewbee[/eluser]
And now I understand why it was done the way it is...

System/Codeigniter/Codeigniter.php
(this is not a class mind you)
Code:
// Call the requested method.
        // Any URI segments present (besides the class/function) will be passed to the method for convenience
        call_user_func_array(array(&$CI, $method), array_slice($URI->rsegments, 2));

This will be an interesting one to tackle indeed...

I know this can be easily handled in PHP 5 using the reflection methods, but PHP 4?




Theme © iAndrew 2016 - Forum software by © MyBB