Welcome Guest, Not a member yet? Register   Sign In
problem with uri routing.
#1

[eluser]Bramme[/eluser]
Hey all,

I'm using URI routing on a site I'm making. But I ran into a problem as I was cleaning up my controller.

The url /news/offset/5 gets rerouted to my content controller, so without uri routing, 5 would be the 4th uri segment. Now, all should work fine if I use this:
Code:
function news($type, $string = 'offset', $offset) {
However, it doesn't. I get an error: "Missing argument 3 for Content::news()"

If I use $offset = 0 (which I should, using pagination) $offset just stays 0...

edit: using /news/offset/5 or /news/offset/5/ doesn't make a difference Sad I hoped it would, then it'd just be a bug. Now I can't figure out what's wrong. Because
Code:
$test = $this->uri->segment(3);
echo $test;
works fine in the same method.
#2

[eluser]Bramme[/eluser]
I don't know if this is important, but I've moved my folders around a bit...

my folder structure is now

/admin
/admin/admin_application
/admin/index.php (for admin_application, refers to general system folder)
/system
/application
/index.php (for application)
#3

[eluser]Yash[/eluser]
Missing argument -- you can use optional php function.I mean pass a default value
#4

[eluser]Bramme[/eluser]
Yeah, that's the whole problem: if I pass a default value, it'll always be the default value... that's the whole problem, even though the uri strings are there, they're not being recognized!
#5

[eluser]Colin Williams[/eluser]
Code:
function news($type, $string = 'offset', $offset)

This is such a no-no! From the PHP docs (em. mine):

Quote:Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected.

What is stopping you from doing:

Code:
function news($type, $string = 'offset', $offset = FALSE)
#6

[eluser]Bramme[/eluser]
Okay, I feel really stupid. I got mixed up using my routes. $type is completely in the wrong place and needs to be chucked out, then everything works like a charm.

My route looks like this: $route['(.*)'] = 'content/$1'; so offcourse my /news/offset/5 uri was causing havoc.




Theme © iAndrew 2016 - Forum software by © MyBB