Help with virtual directories - 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: Help with virtual directories (/showthread.php?tid=10999) |
Help with virtual directories - El Forum - 08-21-2008 [eluser]cmgmyr[/eluser] Hello all, Hopefully this will be a quick answer but I couldn't find it anywhere. I would like to do something like this: domain.com/{username} (controller 1) domain.com/{username}/controller2 domain.com/{username}/controller3 Example: domain.com/cmgmyr (profile page) domain.com/cmgmyr/friends domain.com/cmgmyr/friends/add domain.com/cmgmyr/music domain.com/cmgmyr/music/vote How do I set it up so that I can pass the user name to a function, get the userid, then pass that to the other controllers/functions? Thanks in advance. -Chris Help with virtual directories - El Forum - 08-21-2008 [eluser]drewbee[/eluser] I would actually do it a little bit differently. The way you are requiring is that the username (any) is the controller. You could do it with routing, but it leaves a little to much.... open if you ask me. I havn't tested this, so you will need to adjust it properly. But I would imagine something along these lines coupled with the right routing rules you could do the following: domain.com/user/cmgmyr/ domain.com/user/cmgmyr/friends/ domain.com/user/cmgmyr/music/ domain.com/user/cmgmyr/music/vote Code: controller User extends Controller() I hope this gives you the general idea of what your looking for. Help with virtual directories - El Forum - 08-21-2008 [eluser]cmgmyr[/eluser] Thanks for the reply. I see where that would be a lot easier to do, but the problem is with the seo and current structure of the site I would have to do that as a last resort. Also I would need to make sure I can still have other pages to the site also. Like: domain.com/about, domain.com/contact Thanks! -Chris Help with virtual directories - El Forum - 08-21-2008 [eluser]drewbee[/eluser] Other pages would not be a problem with that. Those are simply more controllers. Code: class About extends Controller() Im not sure what you mean by SEO either. You can't much more SEO friendly then what code igniter gives out of the box! Help with virtual directories - El Forum - 08-21-2008 [eluser]cmgmyr[/eluser] Thanks again for the reply. Sorry about the SEO I should have been more clear. I don't want to lose the current site setup. The current site is domain.com/cmgmyr and I would like to convert it to CI, but I don't want to lose what I already have up on the web. Make more sense? Thanks! -Chris Help with virtual directories - El Forum - 08-23-2008 [eluser]ehicks727[/eluser] [quote author="cmgmyr" date="1219386500"]The current site is domain.com/cmgmyr and I would like to convert it to CI, but I don't want to lose what I already have up on the web. [/quote] Just 301 redirect your pages in your .htaccess file. You won't lose anything. I've redirected thousands of pages this way, necessary because of a change in strategy or planning, and you don't lose your 'Google juice', so to speak. Help with virtual directories - El Forum - 08-23-2008 [eluser]@li[/eluser] Just setup routes for all the static pages like About etc to the controller, then do a /:any/ route to the user controller. In the user controller itself you can validate the username being passed, also CodeIgniter disallows any characters other than a-z0-9-_ etc in the url, so I don't see any security issues with this at all. Help with virtual directories - El Forum - 08-24-2008 [eluser]cmgmyr[/eluser] Thanks @li, that sounds like it would work out. There are only a few static pages so this wouldn't be too much work. Thanks again for the help! |