CodeIgniter Forums
Route into a controller sub-directory - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Route into a controller sub-directory (/showthread.php?tid=5656)

Pages: 1 2


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]Edemilson Lima[/eluser]
I am having a problem with a routing...

At my routes.php, I have:

Code:
$route['([a-z]+)/([0-9]+)'] = "$1/details/index/$2";

If I go to: http://www.site.com/products/details/index/3
It works fine.
But, if I do it by the route: http://www.site.com/products/3
It calls products/details/index, but does not send the id code:

Code:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Details::index()
Filename: products/details.php
Line Number: 11

"products" is a folder, "details" is the controller and "index" is its default function.


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]wiredesignz[/eluser]
after a lot of testing I found this route works instead oddly enough:
Code:
$route['([a-z]+)/([0-9]+)'] = '$1/details/index/$0';

Can someone explain or do a check on this please.

TIA


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]xwero[/eluser]
is
Code:
$route['([a-z]+)/([0-9]+)'] = "$1/details/$2";
working?


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]Edemilson Lima[/eluser]
No. This was my first try. It returns a 404 page.


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]Edemilson Lima[/eluser]
Code:
$route['([a-z]+)/([0-9]+)'] = '$1/details/index/$0';

This worked for me too! Well, I will use it until another solution be provided.


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]Derek Jones[/eluser]
Some threads are coming close to crossing one another here, but to be thorough, try updating from the SVN, as a related bug was fixed yesterday.


Route into a controller sub-directory - El Forum - 01-30-2008

[eluser]Edemilson Lima[/eluser]
No problem, I will wait for the next CI release. =)

My first CI-based project is in the beginning anyway.


Route into a controller sub-directory - El Forum - 01-31-2008

[eluser]wiredesignz[/eluser]
Well you didn't have to wait too long after all.


Route into a controller sub-directory - El Forum - 01-31-2008

[eluser]sophistry[/eluser]
I grabbed the 1.6 release from the download page today (20080131) and I am seeing these same bugs when using regex routing (my controller is not in sub-dirs):

http://ellislab.com/forums/viewthread/48779
http://ellislab.com/forums/viewthread/50795/

to sum up... regex routes set segments properly but don't send them as controller parameters properly.
so, when i put a regex route like this:

Code:
$route['[a-z]{3}'] = "welcome/index/$1";

the parameter sent to the controller function is the literal string dollarsign1 ($1). I also tried $0 and that did the same thing.

but, the segment_array() method shows the right data - it has the string captured by the regex.

i checked the bug forum and this was the latest talk about it.

is this expected behavior? should i just use the $this->uri->segment(n) method and be done?


Route into a controller sub-directory - El Forum - 01-31-2008

[eluser]Edemilson Lima[/eluser]
Did you try the expression inside parenthesis?

Code:
$route['([a-z]{3})'] = "welcome/index/$1";

Aren't the parenthesis that determine what will become $1, $2, $3, etc?