Controller Names with Dashes or Underscores? |
[eluser]Dam1an[/eluser]
@narcisha: The URL friendly part of the URL is normally the 3rd part, such as the name of a blog post etc (it may appear as the first or second, but its not really) I've never found the need to use hyphens or underscores in controller names/functions, just in the parameters
[eluser]aidehua[/eluser]
Forget search engine friendliness for a minute. I think Quote:example.com/about-usis more human-friendly than Quote:example.com/about_us For now I'm using routes to achieve this: Code: $route['about-us'] = "about_us"; But it could get tedious if I have dozens of pages to set up like that: Code: $route['about-us'] = "about_us"; (You might say that these are trivial examples, and the pages could simply be re-named "about", "contact", and "terms" with no loss of usability - but there will be cases when I really do want to keep the dashes in the URI.) And what if I'm creating pages (and URIs) dynamically through a content management system? Should I be writing a new line to my routes.php file automatically when I create a new page through the CMS? That feels a bit clunky. If I were clever with regular expressions, maybe I could write something in routes.php that does this: Code: $route['[string-with-dashes-in-first-or-second-uri-segment'] = "[string-with-underscores-in-first-or-second-uri-segment]"; But I'm not clever with regular expressions. (Anyone?) Or would it be better to do this by customising the router library?
[eluser]Stephen G[/eluser]
Hi :-) ![]() I made this change to the systems routers file and it seems to work great!!! =O) Code: //STEVE CHANGED
[eluser]sumanchalki[/eluser]
Hi guys! I found a solution of this and posted in stackoverflow.com. Here is the link. http://stackoverflow.com/questions/24281...05#2432405
[eluser]e-mike[/eluser]
Code: <?php Put this file MY_Router.php inside /application/libraries (CI1) or /application/core (CI2) Remember that this will effect all segments, not only module, controller and method. Alternative to this extend is to add each segment to router.php $route['this-is-a-module-or-controler'] = 'this_is_a_module_or_controller'; As you can see the extend method would be easier to use. You can choose to make the function also to handle only the first two or three segments so that the other segments are not affected with the _ replacement.
[eluser]Unknown[/eluser]
Hello everyone, here is my solution on CI version: 2.0.2 .... extend Route Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Welcome Guest, Not a member yet? Register Sign In |