开发者

Make localhost/ call a controller in CodeIgniter

I am using codeigniter and am using an .htaccess to rewrite localhost/index.php/some_class as localhost/some_class.

How can i have localhost/ itself call a certain controller? as in localhost will be a class and localhost/some_func would be possible.

EDIT:

This is my current .htaccess:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^开发者_开发问答(.*)$ /index.php/$1 [L] 


You want to to edit application/config/routes.php

$route['default_controller'] = "some_class";

By changing the default_controller, this will call the index function of some_class. You will not be able to call localhost/my_function where my_function belongs to some_class using this method.

Edit:

I misread your post, you want to edit your htaccess file to redirect everything to some_class. If you post your .htaccess we can help you out.

Something like this:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|stylesheets|scripts|robots\.txt)
RewriteRule ^(.*)$ /index.php/some_class/$1 [L]

Note: This sort of goes against the MVC structure.


Yes, you will have to define a default controller that will execute its index function when you call localhost/

but, you can also do the other thing you were thinking, to catch directly with a method of that controller without the controller name

localhost/some_func

you need to use wildcards in routes, here is how

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜