CodeIgniter Forums

Full Version: Remove controller name for affiliate system
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]Mantero[/eluser]
I'm currently adding affiliate system to my site.

currently my affiliate agent can use URL like this:

http://www.mysite.com/affiliate/mantero

'mantero' is affiliate id which is unique and dynamic

my problem is how I'm able to remove the controller name in URL and they can just use like this:

http://www.mysite.com/mantero

My appologies if this has been asked before..but I really could'nt find any solution for my exact problem

thanks in advanced

El Forum

[eluser]Mantero[/eluser]
just to add I also have another controller..so is it possible to use routes? how if so..

thanks

El Forum

[eluser]Rok Biderman[/eluser]
If you add this into config/routes.php it should do the trick:

Quote:$route['mantero'] = 'affiliate/mantero';

El Forum

[eluser]Mantero[/eluser]
[quote author="Coccodrillo" date="1297709044"]If you add this into config/routes.php it should do the trick:

Quote:$route['mantero'] = 'affiliate/mantero';
[/quote]

how I'm supposed to do that..that 'mantero' is the ID which is unique and dynamic..it just an example...

if I have thousands of ID I don't think I can make a routes for all that...

El Forum

[eluser]Rok Biderman[/eluser]
in that case:

Code:
$route[‘(:any)’] = ‘affiliate/$1’;

El Forum

[eluser]cideveloper[/eluser]
[quote author="Coccodrillo" date="1297714846"]in that case:

Code:
$route[‘(:any)’] = ‘affiliate/$1’;
[/quote]

That will not work since he has other controllers. Thus his other controllers will be routed to "affiliate/controller_name". I dont really have a solution but I just know this did not work for me. If I am wrong please let me know so I can fix my code.

Maybe hooks are a better solution?

El Forum

[eluser]Mantero[/eluser]
[quote author="cideveloper" date="1297716662"][quote author="Coccodrillo" date="1297714846"]in that case:

Code:
$route[‘(:any)’] = ‘affiliate/$1’;
[/quote]

That will not work since he has other controllers. Thus his other controllers will be routed to "affiliate/controller_name". I dont really have a solution but I just know this did not work for me. If I am wrong please let me know so I can fix my code.

Maybe hooks are a better solution?[/quote]

yes, the problem is because I have other controller as well..

can we make exception for the routes?

I mean if I have Controller1,Controller2,Controller3, except all these controller will goes to affiliate controller...are this possible?

El Forum

[eluser]Mantero[/eluser]
I mean like this

Code:
$route['^(?!controller1|controller2|controller3).*'] = "affiliate/$0";

El Forum

[eluser]Rok Biderman[/eluser]
Why wouldn't this work?

Code:
$route['otherroute/(:any)'] = "othercontroller/$1";
$route["(:any)"] = "affiliates/$1";

El Forum

[eluser]Mantero[/eluser]
[quote author="Coccodrillo" date="1297718408"]Why wouldn't this work?

Code:
$route['otherroute/(:any)'] = "othercontroller/$1";
$route["(:any)"] = "affiliates/$1";
[/quote]

$route['otherroute/(:any)'] = "othercontroller/$1";<--that mean I have to define the route for each of my controller?
Pages: 1 2