CodeIgniter Forums
nice referral link - 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: nice referral link (/showthread.php?tid=16519)



nice referral link - El Forum - 03-09-2009

[eluser]Dariusz-Gdynia[/eluser]
is there any chance to produce nice-looking referral link in CI?
I know I can have www.domain.com/controller/function/id but can I have something else?

I need to read idUser from that link, move it to $this->session->userdata, and finally use it when somebody is going to register.


nice referral link - El Forum - 03-09-2009

[eluser]pistolPete[/eluser]
[quote author="Dariusz-Gdynia" date="1236627731"]I know I can have www.domain.com/controller/function/id but can I have something else?[/quote]

You can do almost everything you want to (using routing / .htaccess etc.), but if you don't specify how it should look like it's hard to tell.


nice referral link - El Forum - 03-09-2009

[eluser]Dariusz-Gdynia[/eluser]
the shorter the better I think. So if it could be like www.domain.com/124 it would be great. But I have no idea how :/


nice referral link - El Forum - 03-09-2009

[eluser]pistolPete[/eluser]
Well then read the user guide about URI Rouing.


nice referral link - El Forum - 03-09-2009

[eluser]Dariusz-Gdynia[/eluser]
that works almost great Smile I have www.domain.com/recomend/124

As I presume the is no option for www.domain.com/124 ?


nice referral link - El Forum - 03-09-2009

[eluser]pistolPete[/eluser]
Try something like this:
Code:
$route['(:num)'] = "controller/method/$1";
This only works if the ids are numerical.


nice referral link - El Forum - 03-09-2009

[eluser]drewbee[/eluser]
I actually had a requirement for this, except for the fact that it could be attached to ANY uri. Obviously i wasn't going to hard code this into every controller.

I used the pre_controller hook to handle this situation as well as cookies.

Pre Controller hook: (note: most of CI is not intiallized by this point, so we just have to do some good old fashion PHP'in here);

Code:
if (isset($_GET['refid'))
{
    setcookie('refid', $_GET['refid'], strtotime('3 months'), '', '/');
    // We have to unset the get variable so codeigniter doesn't freakout about it
    unset($_GET['refid']);
}

Now anywhere in our application we can simply retrieve the cookie data as needed.

As well, any page can now be used as a referal page.

/controller/method/param/param.html?refid=drewbee

/controller.html?refid=drewbee

etc.


nice referral link - El Forum - 03-10-2009

[eluser]Dariusz-Gdynia[/eluser]
[quote author="pistolPete" date="1236630567"]Try something like this:
Code:
$route['(:num)'] = "controller/method/$1";
This only works if the ids are numerical.[/quote]
after that I tried www.domain.com/1 and it's not working...
Code:
404 Page Not Found
The page you requested was not found.

drewbee => the case is short URL, not retrieving id Smile


nice referral link - El Forum - 03-10-2009

[eluser]pistolPete[/eluser]
How does your route look like?

controller/method/$1 was just an example, you have to adjust it according to your controllers/methods.


nice referral link - El Forum - 03-11-2009

[eluser]Dariusz-Gdynia[/eluser]
yes, yes, I know that Smile

In my case it is
$route['recommend/(:num)'] = "welcome/index/$1";
$route['(:num)'] = "welcome/index/$1";

in first case it's working in second it doesn't, I tried even with slash $route['/(:num)'] and still nothing :/