![]() |
Using MY_Router.php to allow for hyphenated URL's - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Using MY_Router.php to allow for hyphenated URL's (/showthread.php?tid=59134) |
Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-28-2013 [eluser]beneck[/eluser] I am trying to find a way to make more SEO friendly URL's with CI. I come from the train of thought that Hyphens are easier delimiters in a URL than underscores are. Preferred: http://mysite.com/controller/method-name OR http://mysite.com/controller-name/method-name Default CI: http://mysite.com/controller/method_name OR http://myseite.com/controller_name/method_name Obviously CI is simply mapping the method name, and in PHP you can't have hyphens in method/function names. I came across a thread that suggested I extend CI_Router with MY_Router. The idea is to to a string replace in the first two segments only and change out hyphens for underscores (this way, the rest of the URL is left alone and maps as planned). I have created the following class and placed in the core directory. However, the class is not being instantiated by itself. I was able to use the autoload feature to load it, however the routes aren't being passed through it. I verified in the config.php file that "MY_" is the prefix for custom files. Is it in the right directory (core)? Do I need to autoload it? How do I make sure it's used? Here is the code in my MY_Router.php file. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-28-2013 [eluser]CroNiX[/eluser] Well, only things extended from /system/core would go in /application/core. That library is in /system/libraries, so your extension would go in /application/libraries. Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-28-2013 [eluser]beneck[/eluser] In my install... Router.php is located in system/core/Router.php. There is no Router.php file in the system/library/ folder. Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-28-2013 [eluser]InsiteFX[/eluser] It's very simple: If your extending from system/core it go's in application/core. If your extending from system/libraries it go's in application/libraries. Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-28-2013 [eluser]beneck[/eluser] So based on what you are saying, my file IS in the correct folder. So why is it not instantiated and used by the system? Is there something else I need to do? Using MY_Router.php to allow for hyphenated URL's - El Forum - 08-29-2013 [eluser]InsiteFX[/eluser] You can try adding this and see if it works to your config.php file at the bottom! Code: /* |