Welcome Guest, Not a member yet? Register   Sign In
URI Routing: Why my controllers function does'nt care about the defaults?
#1

[eluser]F. Albrecht[/eluser]
Hi all,

I'm just porting a procedural PHP project to CI and it rocks. The code is cleaner, compacter, better to read and will scale in the future...

At the moment I have one question about URI routing:

Code:
$route['(my_link)/?(:any)?/?'] = "my_controller/my_function/$1/$2";

In my_controller.php:

Code:
function my_function($foo, $bar = 'foo')
{
    echo "bar = " . $bar;
}

The link

Code:
www.domainname.tld/index.php/my_link/12

generates

Quote:bar = 12

The link

Code:
www.domainname.tld/index.php/my_link

generates

Quote:bar =

but should generate

Code:
bar = foo


A vardump via

Code:
var_dump($bar);

says

Quote:string(0) ""

What happens to my 'foo'? Anything wrong with my route/logic/code?

I guess that a possible workaround this

Code:
if ( !empty($this->uri->segment(2)) ) make foo else make bar

or this

Code:
if ( !empty($bar)) ) make foo else make bar

snippet is?

Thanks for reading!


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



Theme © iAndrew 2016 - Forum software by © MyBB