EllisLab text mark
Advanced Search
User subfolders like Twitter ?
Posted: 10 May 2009 11:24 AM
Joined: 2009-05-10
7 posts

Is there a way to create user subfolders automatically when you create an account like Twitter does (i.e. mywebsite.com/usersubflolder)with code igniter?
I’m working on social media app. that requires that and I don’t know how to go about it.

Thank you!

Posted: 10 May 2009 11:29 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2008-05-18
2398 posts

Are you actually on about creating folders, or somethink like discussed here (there’s several more threads about this already, this one was top of the pile)


I’m building a Project Management System for my 3rd year Uni project, Sign up to the beta
Track my progress | Post of the day: UI Designs
Get full auto complete support for CodeIgniter in Eclipse

Posted: 10 May 2009 11:31 AM   [ # 2 ]   [ Rating: 0 ]
Joined: 2009-05-10
7 posts

That was a quick response. Thank you much, I’ll take a look a the link you’ve provided.

Posted: 10 May 2009 11:34 AM   [ # 3 ]   [ Rating: 0 ]
Joined: 2009-03-21
680 posts

You wouldn’t actually create subfolders.  Sites like Twitter are database driven, so they would be crazy to create a million subfolders.  Check out the CI user guide, it talks about URI structure in the controller section:


Also, you’ll probably want to have a look at the routes section:

Posted: 10 May 2009 11:44 AM   [ # 4 ]   [ Rating: 0 ]
Joined: 2009-05-10
7 posts

Now, may I ask if there is already some pre-built code that will do just that, create a user account and also create a user (virtual)subfolder?

Posted: 10 May 2009 12:07 PM   [ # 5 ]   [ Rating: 0 ]
Joined: 2009-03-21
680 posts

You may ask.

I doubt there would be anything to do this automatically, as everyone’s needs would be different when it comes to user accounts.

Also, you’re not really ‘creating’ a user’s virtual subfolder.  Instead, you’re accessing their account dynamically by using the first URI segment.

So basically you access something like http://www.domain.com/jimmydean, and in your default controller you use the first URI segment to retrieve the user’s profile from the database.

Posted: 11 May 2009 12:22 AM   [ # 6 ]   [ Rating: 0 ]
Joined: 2008-12-01
6 posts

you could also just use .htaccess to do the same thing.

Posted: 12 May 2009 06:10 PM   [ # 7 ]   [ Rating: 0 ]
Joined: 2009-05-10
7 posts

How can I use the .htaccess to do this?

Posted: 12 May 2009 08:37 PM   [ # 8 ]   [ Rating: 0 ]
Joined: 2009-03-21
680 posts

You really can’t.  An .htaccess file allows you to set server directives, so you could use it to restrict files or folders, but you’d need to add each user to it, either manually or through a script.  You’d also need to create and maintain passwords for those users.  All that would do is allow them access to a particular folder, it wouldn’t create folders for each user.

What exactly are you trying to do?  What will your app do?  How much have you done so far?  What will a user see when they visit http://www.yourdomain.com/username?

The more information you can provide about what you’re trying to accomplish, the easier (and thus, more likely) it will be for someone to prescribe a solution.

Also, the codeigniter user guide is VERY thorough, it provides you with enough information to do what you’re trying to do.  So if you’re asking for help with things that are already in the user guide, you’re really just wasting time.

Posted: 12 May 2009 08:51 PM   [ # 9 ]   [ Rating: 0 ]
Joined: 2007-06-11
2987 posts

@slowgary: You are massively confusing this one. codecode is simply looking for a non-intrusive method to route all example.com/username requests to something like example.com/users/profile/username. This CAN be done with routes or by extending the router.

Please search around using Google or the search bar for this as I have seen it answered so many times I made a bloody blog post about another method.


Blog | Twitter | GitHub | BitBucket
PyroCMS - open source modular CMS built with CodeIgniter
PancakeApp - Simple, hosted invoicing/w project management

Posted: 12 May 2009 09:32 PM   [ # 10 ]   [ Rating: 0 ]
Joined: 2008-07-16
411 posts

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.


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.


My Blog, C2D, PHP Videos, Résumé, Super .htaccess, Extra hooks, and MicroMVC

Posted: 13 May 2009 02:32 AM   [ # 11 ]   [ Rating: 0 ]
Joined: 2009-05-10
7 posts

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.

Posted: 13 May 2009 03:28 AM   [ # 12 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

You can make the routing simpler by only using the controllers instead of each normal route.


And you can limit the user name which opens the door for identifying user related segments.


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

class Users as Controller

var $username;

$this->username $this->uri->segment(1);
// all the other methods

In the constructor you can verify if the username is valid among other things.

Posted: 11 June 2009 04:41 PM   [ # 13 ]   [ Rating: 0 ]
Joined: 2008-10-06
30 posts

Thanks xwero, I think thats the cleanest solution I’ve seen or thought of… looks good.

Good clean username urls



Posted: 11 June 2009 06:49 PM   [ # 14 ]   [ Rating: 0 ]
Joined: 2008-10-06
30 posts

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.

$controllersDir APPPATH."/controllers";

$controllers = array();

foreach (
scandir($controllersDir) as $file)

$filename[1] == "php")


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


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.