This is the most simple way I can ask this question as I have not fully understood what's going on, or what I am not doing right.
I'm having trouble with the url.
http://localhost/index.php/user is the same as http://localhost/
but
http://localhost/index.p开发者_高级运维hp/user/something is not the same as http://localhost/something
How do I make http://localhost/something work?
Does it have to be http://localhost/user/something, how do I make that work?
You need to understand how CodeIgniter's URLs work.
An URL consists of some segments.
http://localhost/index.php/user/something/thingIn this exampleuser,somethingandthingare segments of the URL.Segments of the URL indicate which controller and which method of that controller will run.
http://localhost/index.php/user/something/thingIn this example the methodsomethingfromusercontroller is called andthingis passed to that method as a parameter.The first segment of the URL indicates the controller.
The second segment of the URL indicates the method of that controller.
The following segments are sent to that method as parameters.
But there are some defaults.
If your URL is
http://localhost/index.php/something, you havesomethingspecified as the controller, but because you have not specified any method, the default method which isindexis called. So the above URL is the same ashttp://localhost/index.php/something/indexIf your URL is
http://localhost/index.php/, you don't have any segments specified (no controller and no method). So the default controller which is specified inapplication\config\routes.phpis the loaded controller. Which method of that controller will be called? Of course theindexmethod.--You can set the default controller by changing
$route['default_controller'] = "site";to what ever fits your application inapplication\config\routes.php's file.If you want
http://localhost/user/somethingto be the same ashttp://localhost/index.php/user/something, you have to create custom routes for your application. More info on that here.
http://localhost/something indicates that you are calling the index method of the Something controller class
http://localhost/user/something indicates that you are calling the something method in the User controller class.
Does that make sense?
In order to make http://localhost/something work, you need a controller called something with an index method. This would be the same as accessing http://localhost/something/index.
Alternatively, http://localhost/user/something implies that you have a user controller with a method called something.
Does that help at all?
To remove index.php from your URL you have to use the mod_rewrite method described here
Then to remove the controller name (user) from the url, you need to use routes
In your case, you would add $route['^(something|something_else|etc)(/:any)?$'] = "user/$0"; to your routes.php file
加载中,请稍侯......
精彩评论