CodeIgniter Routes: I keep getting 404

I have a file application / controller / login.php containing the following

class Login extends Controller { function Login() { parent::Controller(); } function index() { $this->mysmarty->assign('title', 'Login'); $this->mysmarty->assign('site_media', $this->config->item('site_media')); $this->mysmarty->display('smarty.tpl'); } } 

My route definition is as follows:

 $route['default_controller'] = "welcome"; $route['login'] = 'login'; $route['scaffolding_trigger'] = ""; 

The problem is that I get 404 when I try to access http: // localhost / myapp / login . What have I done wrong? I checked the CI route documents and cannot find anything.

+4
source share
3 answers

There should be nothing wrong with this - does it work without a route? In addition, you configured .htaccess correctly (i.e. instead of http: //localhost/myapp/index.php/login )

+7
source

Another point to keep in mind if you have "enable_query_strings" set to true and not using .htaccess mod_rewrite rules:

In config / config.php:

 $config['enable_query_strings'] = TRUE; $config['controller_trigger'] = 'c'; $config['function_trigger'] = 'm'; $config['directory_trigger'] = 'd'; 

The URL for the correct direction of your request will look like this:

 http://localhost/myapp/index.php?c=login 
+2
source

If you have not removed your index.php from your application using the .htaccess file, well, this is another ball game in itself. But you can do the following:

Set the default controller , not the welcome file, and if you want the welcome file to be your default, use the link this way

 http://localhost/myapp/index.php/login 

Remember that this method only works when the index.php file has not been deleted using the .htaccess file.

Also open apllication/config/config.php and use this code for baseurl

 $config['base_url'] = 'http://localhost/myapp'; 

This should always do the trick.

0
source

All Articles