• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routing a controller - how to dismiss certain functions?

#1
[eluser]loathsome[/eluser]
Hello,

I'm currently developing an application, and for this I have a signup-controller. As a first parameter in the index function I have a variable whose purpose is to receive a language code and process it later on. (En, Gb, etc)

Code:
class Signup extends Peeps_Controller {

function index($Lang = false){
/* :D */
}

}

Now, I want to route everything that goes to app/signup to app/signup/index/$1 - EXCEPT "post" and "quick", those should go to app/signup/post - because those are their own functions. I do not want to create another route, but rather do it all in the same using regex - I'm almost there. I've tried
Code:
$route['signup/((.*)|^post|^quick)'] = "signup/index/$1";
but without any luck. To sum it up:

app/signup/whatever should go to app/signup/index/whatever
app/signup/post OR quick should go to app/signup/post OR quick

#2
[eluser]Dam1an[/eluser]
Do you need to explicity say 'anything or not post or not quick'?
Would it not be sufficient for just the (^post|^quick) part?

I may be totally wrong, as I've only used positive matching in my routes

#3
[eluser]xwero[/eluser]
Code:
$route['(signup/)(?!post|quick)'] = '$1$2'; // i fetch the controller too because i'm lazy
That should work, it's a valid regular expression but the negative look ahead isn't implemented in every regex parser.

If that doesn't work you can always do
Code:
$route['(signup/)(post|quick)'] = '$1$2';
$route['(signup/)(.+)'] = '$1$2';

#4
[eluser]Dam1an[/eluser]
Do you not need to do the variables on the right of the expression in double quotes? Otherwise PHP won't parse the values of the $1 and $2? Cause thats the normal case with strings in PHP

#5
[eluser]xwero[/eluser]
double or single quotes don't matter, it's processed internally. You can't even have a variable name that only has digits as a name.

#6
[eluser]Dam1an[/eluser]
I figured that the $1, $2 etc where just placeholders, and would be replaced with the args (bit like in C), but assumed it would need to be double quotes to be processed, just like strings...

I learn something new every day Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


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