Using MY_Router.php to allow for hyphenated URL's |
[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');
[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.
[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.
[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.
[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?
[eluser]InsiteFX[/eluser]
You can try adding this and see if it works to your config.php file at the bottom! Code: /* |
Welcome Guest, Not a member yet? Register Sign In |