URL question |
[eluser]Unknown[/eluser]
I'm trying to send a variable with the value of "the-project-name" to my project controller. It works right now when I send it to the index function: http://mysite.com/project/index/the-project-name/ But how do I circumvent the index function and still send variables and launch the index function? So it looks like this: http://mysite.com/project/the-project-name/ Doing this just gives an error: 404 Page Not Found The page you requested was not found. Here's what my code looks like: Code: <?php How do you do this?
[eluser]srobet[/eluser]
I'm using route to do that. Code: $route['project/(.*)']='project/detail/$1'; in my controller, I create the function detail instead the index. Code: function detail($project_name) and don't need to call the uri->segment in that function, just call the $project_name variable ![]() CMIIW
[eluser]Sumon[/eluser]
The difference between Code: http://mysite.com/project/index/the-project-name/ [code] $route['project/(.*)']='project/index/$1'; [code] Not working. I feel, rewrite rule in .htaccess might be a solution. Sorry to say i don't know how to write .htaccess if (condition) execute instruction code.
[eluser]srobet[/eluser]
I think rewrite rule just clean up the url. You can try by type http://yoursite.com/index.php/project/the-project-name with no .htaccess.
[eluser]Sumon[/eluser]
The question seems to me, 'the-project-name' treat as function name rather then parameter or segment while we remove index.php or index. So if we are able to place index in between http://mysite.com/project/ and the-project-name then the full uri path (apache treat) will become http://mysite.com/project/index/the-project-name. Well at this point, lets consider the following .htaccess code Code: Options +FollowSymLinks Code: RewriteRule ^(.*)$ /index.php/$1 [L] Now to resolve our issue we need to write this sort of index placement in between but surely with a condition like: if the request url have project as first segment then we add index in the middle. hope help you.
[eluser]Michael Wales[/eluser]
Routes are what you want to use, something like this will work perfectly: Code: $route['project/([a-zA-Z0-9-]+)'] = 'project/index/$1'; Note: This will only match project/slug-here, not project/slug-here/ (note the trailing slash).
[eluser]Sumon[/eluser]
I am using Code: $route['project/([a-zA-Z0-9-]+)'] = 'project/index/$1'; Here is my test controller. Code: <?php Code: 404 Page Not Found But works fine for http://localhost/shopno-dinga/project/index/test_value
[eluser]srobet[/eluser]
Hm.... I always use that method for uri manipulation and works. Can you try new function instead index like : Code: function index() and reroute your routing to this function. Tell me it works or not
[eluser]Sumon[/eluser]
Thanks but the question is now how we can utilize CI route power by using Code: $route['project/([a-zA-Z0-9-]+)'] = 'project/index/$1';
[eluser]Michael Wales[/eluser]
Sumon - you are saying routing does not work if you are routing to the index() method? For example, if you changed the route to show_page, like srobet suggested, it works? Two thoughts here: 1) If my description above is correct, we should submit a bug report about it. 2) show_page is a much better name than index() because it actually tells you what the method does. I've always been a fan of routing and you will hear me say over and over - the class/methods have nothing to do with the URI. It's a nice side benefit but never rely on it, if you want a specific URI, define it. This is the perfect example where a method could be named much more descriptively and routing could do it's job. |
Welcome Guest, Not a member yet? Register Sign In |