views:

1027

answers:

2

Hi all,

I just moving my first steps with Code Igniter, so please bear with me.

I have a application/controller/login.php file 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 routes definition looks like the following:

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

The problem is that i keep getting a 404 when i try to access http://localhost/myapp/login. What did i do wrong? I've checked CI routes docs and cannot spot anything.

Thanks

+4  A: 

There shouldn't be anything wrong with this - does it work without the route? Also, have you set the .htaccess properly (i.e. does http://localhost/myapp/index.php/login work instead)

v3
Thanks v3 that did it. But why doesn't the default_controller need the index.php?
L. De Leo
By default, if you go to a folder on the web server Apache looks for index.html, index.php, main.php, etc.So http://localhost/myapp/ is equivalent to http://localhost/myapp/index.php.
v3
A: 

Another point to keep in mind, if you have have "enable_query_strings" set to true and aren't using the .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 to route your request properly would look like this:

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