• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
URI Routing: Why my controllers function does'nt care about the defaults?

#3
[eluser]F. Albrecht[/eluser]
Hi wiredesignz,

thanks a lot.

I've noticed yesterday that the default parameter is/are valid, if I DON'T route any of the NEEDED default parameter(s) to the controller via routes.php. This works:

Code:
$route['test/?(.*)?/?'] = "page_controller/my_test";

Code:
function my_test($bar1 = 'foo1', $bar2 = 'foo2')
    {
        echo "bar1 = $bar1<br>";
        echo "bar2 = $bar2";

    }

And I can combine both methods:

Code:
$route['test/?(.*)?/?'] = "page_controller/my_test/$1";

Code:
function my_test($CIpassed,$bar1 = 'foo1', $bar2 = 'foo2')
    {
        echo "CIpassed = $CIpassed<br>";
        echo "bar1 = $bar1 <br>";
        echo "bar2 = $bar2";
    }

If I add a tailing slash in

Code:
$route['test/?(.*)?/?'] = "page_controller/my_test/$1/";

the next segment will be set empty through CI.


At the moment I'm not able to recognize the benefits of any of these ways. Perhaps the combination of both to mark down more complex routes...


What do you think?


Edith says: I've just played a little bit the routes and it seems to be that everything is possible. Another variante, especially in view to a generic controller for unlimited hierarchic "static" sites:

Code:
$route['(.*)/?'] = "page_controller/my_test/$1";

Code:
function my_test($CIpassed,$bar1 = 'foo1', $bar2 = 'foo2')
    {
        echo "CIpassed = $CIpassed<br>";
        echo "bar1 = $bar1 <br>";
        echo "bar2 = $bar2";
    }

Then you have only to set the exceptions for individual controllers like gallery, blog etc. in routes.php...


Messages In This Thread
URI Routing: Why my controllers function does'nt care about the defaults? - by El Forum - 05-18-2008, 07:16 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.