Welcome Guest, Not a member yet? Register   Sign In
User subfolders like Twitter ?
#11

[eluser]Xeoncross[/eluser]
Here is how I do it in PHP. You can also do the same thing with htaccess and easier - I just haven't gotten around to it.


Code:
$route['controller/method/'] = "controller/method/";
$route['controller2/method2/'] = "controller2/method2/";
$route['controller3/method3/'] = "controller3/method3/";
$route['(:any)'] = "users/profile/$1";

It's a pain - but you have to set a route rule for each normal controller/method/+-uri_data/. I think you can also use regex in the routes - but I haven't looked into that.
#12

[eluser]codecode[/eluser]
Again, what I need is a user registration process the way Twitter does it and after registration the user to have his/her space like http://mywebsite.com/userid.

I'm not sure how this can be integrated with DX Auth library but that's what I'm trying to do and I need help with. I don't have any code written for this yet other than DX Auth library installed but I just need some advice (sample code) how this can be done (dynamically).
When the user registration is complete the user space (i.e. http://mywebsite.com/userid ) is complete and only that user has access to the functions (like edit, add post etc) on that page (user space), again the way Twitter does it.
#13

[eluser]xwero[/eluser]
You can make the routing simpler by only using the controllers instead of each normal route.
Code:
$route['(controller|controller2)(.*)'] = '$1$2';
And you can limit the user name which opens the door for identifying user related segments.
Code:
$route['[a-zA-Z0-9]+/(add|edit)'] = 'users/$1';
$route['[a-zA-Z0-9]+'] = 'users/profile';
If you don't catch the username itself you can always get it using $this->uri->segment(1) instead of adding a parameter to each method. If it all takes place in the users class you can do
Code:
class Users as Controller
{

    var $username;

    function Users()
    {
        parent::Controller();
        $this->username = $this->uri->segment(1);
    }
    // all the other methods
}
In the constructor you can verify if the username is valid among other things.
#14

[eluser]jwright[/eluser]
Thanks xwero, I think thats the cleanest solution I've seen or thought of... looks good.

Good clean username urls
#15

[eluser]jwright[/eluser]
here's a little modification to xwero's solution ...

it's definately a hack but I'm thinking I won't have to remember to maintain the list of controllers.

Code:
$controllersDir = APPPATH."/controllers";

$controllers = array();

foreach (scandir($controllersDir) as $file)
{
    $filename = explode(".",$file);

    if($filename[1] == "php")
        array_push($controllers, $filename[0]);
}

$regex = "(".implode("|", $controllers).")";

log_message('info', "controllers in route:" . $regex);

$route[$regex.'(.*)'] = "$1$2";

Use this code at your own risk. If I don't have any issues because of this code I'll run it in a production app. Otherwise, just hard coding the controllers isn't a big deal. I love doing stuff like this though.




Theme © iAndrew 2016 - Forum software by © MyBB