Welcome Guest, Not a member yet? Register   Sign In
Lovely User URLS (http://domain.net/~Username)
#11

[eluser]Dyllon[/eluser]
I had to do this a while ago, I didn't want to use URL suffixes so I extended the CI Router as follows

application/libraries/My_Router.php
Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("users","profile",$segments[0]);
            
        }
    }
    return parent::_validate_request($segments);
}
#12

[eluser]Référencement Google[/eluser]
+1 for this Dyllon, this is for me the cleanest way to go and that's how I do it too. Phil's way isn't bad too but it have con's as it can't be portable on every environnement (no avaibility of apache mod_rewrite for example)
#13

[eluser]IamPrototype[/eluser]
[quote author="Dyllon" date="1232421660"]I had to do this a while ago, I didn't want to use URL suffixes so I extended the CI Router as follows

application/libraries/My_Router.php
Code:
class MY_Router extends CI_Router {

    function MY_Router()
    {
        parent::CI_Router();
    }

    function _validate_request($segments)
    {
        // Does the requested controller NOT exist?
        if (!file_exists(APPPATH.'controllers/'.$segments[0].EXT))
        {
            $segments = array("users","profile",$segments[0]);
            
        }
    }
    return parent::_validate_request($segments);
}
[/quote]

So that is basically the same, just another code. I guess I'll have to auto-load the library, right? And then it would work if my controller is named users, and function profile. Smile
#14

[eluser]Phil Sturgeon[/eluser]
You wouldnt need to autoload this, CI would do that for you as it is an extention of the Router library.

This is a good way to do it. Guess mine was a lazy shortcut ;-)
#15

[eluser]IamPrototype[/eluser]
I'll just paste it into my libraries folder, and it should work by itself now, right? Smile
#16

[eluser]Dyllon[/eluser]
that's correct, you'll need to rename the segments depending on your controller/method layout as well.
#17

[eluser]IamPrototype[/eluser]
Yes, sure, thanks a BUNCH!
#18

[eluser]Michael;[/eluser]
I'm not sure I get the logic here of your decision ... Why would you want a URL like http://example.com/userName with, IMO, a lot of extraneous code, when something simple and elegant like http://example.com/profiles/userName would work? Extending the Routing class creates more overhead ( allbeit, not a tremendous amount ) and a profiles controller using the remap function does the trick.

I dunno ... maybe I missed something.

Michael;
#19

[eluser]Phil Sturgeon[/eluser]
I dare you to try that one with a client Michael;. They often want the first URI segment to be the username to be like MySpace, etc and so you will eventually find yourself coding this feature wether you want to or not.
#20

[eluser]Michael;[/eluser]
Pyromaniac,

I will admit, I do not do very much with "social" type sites. By far a vast majority of what I do is content, document, and project management related and typically the client doesn't care what the urls look like so long as they can do X, Y and Z in as few clicks as possible.

Though still ... from an "end user" stand point a user is going to understand what a "profiles" link is far more often than not, say like "facebook" style...

Michael;




Theme © iAndrew 2016 - Forum software by © MyBB