Is possible change the uri (name of controller) in the URL? |
[eluser]jesusruiz[/eluser]
Hello and thanks for reading this message. I hope that you understand what I need to do. I am doing a multilingual website, using CodeIgniter 2.1 internationalization i18n: http://codeigniter.com/wiki/CodeIgniter_...ation_i18n I have two controllers very simple: DEFAULT CONTROLLER: INDEX Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); and CONTROLLER: ABOUT Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I need to make the url for each language could be different, for example: en/about_us es/acerca_de But the problem is that in the url, by default shows the name of the contoller: en/about es/about My code in Routes.php file is: Code: $route['default_controller'] = "index"; Any suggestions or help?. Thousands of thanks and greetings.
[eluser]toopay[/eluser]
You can use : Code: $route['(en|es)/(about_us|acerca_de)'] = "about/$1"; Code: function index($lang = 'en') But with your approach, you mostly will create a bunch of route configuration list. You may consider to extending the core language class, then set more general rule. Less seo friendly perhaps, but it will more maintainable and easy to work with than the previous approach.
[eluser]jesusruiz[/eluser]
Thanks for your help, toopay. I tried the solution given in a reply, but I don't see change in the url. The URL is still: www.site.com/about.html. This hasn't changed to: www.site.com/en/about_us.html or www.site.com/es/acerca_de.html I am beginner in CodeIgniter, so I must be doing something bad. I guess I do not need to use two controllers: about_us (English) and acerca_de (Spanish), because this would be confusing. I'll keep trying, thank you very much for your reply.
[eluser]Samus[/eluser]
[quote author="jesusruiz" date="1333820994"]Thanks for your help, toopay. I tried the solution given in a reply, but I don't see change in the url. The URL is still: www.site.com/about.html. This hasn't changed to: www.site.com/en/about_us.html or www.site.com/es/acerca_de.html I am beginner in CodeIgniter, so I must be doing something bad. I guess I do not need to use two controllers: about_us (English) and acerca_de (Spanish), because this would be confusing. I'll keep trying, thank you very much for your reply. [/quote] Try visit www.site.com/en/about_us.html or change those urls in your viewws
[eluser]jesusruiz[/eluser]
Samus, the result is: 404 Page Not Found. Seems ignore the line added to routes.php. I'll post my code if you see any errors. core/My_Config.php Code: // Originaly CodeIgniter i18n library by Jérôme Jaglale core/My_Lang.php Code: <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
[eluser]jesusruiz[/eluser]
config/routes.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); controllers/about.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); views/en/about.php Code: <div id="container"> This is the current code, although I tried to change the names to view files value, and I get error 404.
[eluser]jesusruiz[/eluser]
I think I've solved it. The problem was in the following two lines: Code: //$route['^en/(.+)$'] = "$1"; Deleting them and leaving only those lines: Code: $route['default_controller'] = "index"; It seems that works OK. Thanks for the help and best regards. |
Welcome Guest, Not a member yet? Register Sign In |