Help w/ URI Routing - Skip class & function calls |
[eluser]Wyndsang[/eluser]
Hello! I started using CI a couple of days ago, and it has been a really effective tool so far. Yet, there is one teensy problem I'm facing. I have a very simple page, and a very simple controller called Page. Page has a function, get_page_by_reference($reference), which fetches mysql data based on a supplied variable, and then constructs a webpage by that data. Page is set as default controller. Now, normally, I assume I would supply $reference like this: Code: example.com/index.php/page/fetch_page_by_reference/reference Code: example.com/index.php/reference Is this possible with $route['']? Also, it would be great if this was only true when there is only one segment following index.php.
[eluser]jmb727[/eluser]
I'm not sure about $route I've never used it before. You could always remove index.php from the url with mod_rewrite. http://ellislab.com/codeigniter/user-gui.../urls.html
[eluser]Wyndsang[/eluser]
Yeah, but that isnät really the issue though. Thing is, I want CI to assume that URI-segments are variables for the function mentioned above, so long as it is the only segment.
[eluser]toopay[/eluser]
[quote author="Wyndsang" date="1311606161"] However, I would like to be able to just supply: Code: example.com/index.php/reference Is this possible with $route['']? [/quote] To achieve the second uri, you need to remove index.php from your uri. How? Simply add .htaccess file, generally that will contain some lines like these : Code: RewriteEngine on After that, you could set your whatsoever route, details : URI Routing
[eluser]Benito[/eluser]
If I understand correctly, you want to reroute Code: example.com/index.php/page/fetch_page_by_reference/reference I don't really understand why you would want to do it this way, because this means that anything passed after yoursite.com/$variable will be run through this controller. In config/routes.php set: Code: $route['(:any)'] = "page/fetch_page_by_reference/"; On the other hand, I would rather do something like: Code: $route['page/(:any)'] = "page/fetch_page_by_reference/$1";
[eluser]Wyndsang[/eluser]
I have now used mod_rewrite to remove the index.php-part of the URI, so that much is solved. @Benito, well, I want to do it the other way 'round, if I understand you correctly. I want visitors to visit a nice, clean URL, such as Code: example.com/pricing And I want routes to assume that, as long as there is only one URI segment, it should be passed as an argument to Page/fetch_page_by_reference The above URL would thus be the equivalent of visiting Code: example.com/page/fetch_page_by_reference/pricing Perhaps worth noting, Page is my default controller. I have tried various approaches using $route['(:any')] to no avail. I either get a Not Found-error, or a CI 404. |
Welcome Guest, Not a member yet? Register Sign In |