Clean urls cannot get function id in CodeIgniter
I am using CodeIgniter in my project and I need to clean the url. I use this htaccess:
RewriteEngine On
RewriteCond $0 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^.*$ index.php [L]
The url redirect is working fine.
If I use localhost/example/controll/
this works fine, if I have an controll
as controller, but if I need to pass a value to the control开发者_C百科ler like localhost/example/controll/how-to-design/
it says 404 not found. Do I need to get the how-to design in controll
class and process it?
the URL localhost/example/controll/how-to-design
translates to a controller called controll
and a method called how-to-design
CI will be looking for a method called how-to-design
, which presumably doesn't exist.
If you want to pass that parameter to controll
the URL needs to be:
controll/index/how-to-design
function index($param)
{
echo $param; // echoes how-to-design
}
you can probably fix this with routing or by using index
in your URI.
You can't by default in CodeIgniter pass parameters to the controller index function - in your example CI would be looking for a method called 'how-to-design' (which in itself is impossible, as dashes are not permitted in PHP function naming conventions).
You can use the special _remap method in your controller to manually handle the routing - http://codeigniter.com/user_guide/general/controllers.html#remapping - or you could set up some manual routes in config/routes.php
write a new function and define custom routes for it in routes.php if you want to achieve it.
精彩评论