prepending vars (useful tip when working with subdomains or multilanguage sites) |
[eluser]smoku[/eluser]
Hello! I moded CI a little bit because I needed to prepend var. With this mod you can create links like: http://www.domain.com/index.php?user=USE...er/method/.... I needed this in order to create user sites with subdomains: USERNAME.domain.com/controller/method => domain.com/index.php?user=USERNAME&/controller/method/ But it could be also very useful with multilanguage sites. You can easily redirect: domain.com/LANG/controller/method => domain.com/index.php?lang=LANG&/controller/method query_strings must be TURNED ON! ---------------------------- Here is the code: Open Router.php In function _set_route_mapping() at the begining change: Code: // Fetch the complete URI string to: Code: // Fetch the complete URI string Add this function to router.php: Code: function _remove_query_strings($string) I don't know if anyone finds this helpful but I needed this in my project so I'm posting this, because I couldn't find it...
[eluser]wiredesignz[/eluser]
Add this to MY_router.php and put it in your application/libraries so you don't break the CI core Extend class MY_router off CI_Router. Code: class MY_router extends CI_Router
[eluser]smoku[/eluser]
[quote author="wiredesignz" date="1201248547"]Add this to MY_router.php and put it in your application/libraries so you don't break the CI core Extend class MY_router off CI_Router. [/quote] I know, this is just a example how to do this, everyone will include this the way they like.
[eluser]Craig A Rodway[/eluser]
Those URLs look awful. Surely there's a better way.
[eluser]wiredesignz[/eluser]
Quote:everyone will include this the way they like. There is only one recommended way to extend/alter the CI core, unless you never plan to upgrade CodeIgniter.
[eluser]smoku[/eluser]
[quote author="Craig Rodway" date="1201276777"]Those URLs look awful. Surely there's a better way.[/quote] You rewrite those URLs using mod_rewrite, the way you did it when you wrote apps without framework. If there is a better way, tell me how to make user's sites: USERNAME.domain.com/controller/method/... (wildcard *.domain.com => domain.com) MY_Router.php: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); |
Welcome Guest, Not a member yet? Register Sign In |