Tutorial :Code Igniter routes



Question:

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


Solution:1

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)


Solution:2

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  


Solution:3

If you have not removed your index.php from your app using the .htaccess file, well thats another ball game on its own. But what you can do is this:

Set a default controller that's 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 this way only works when the index.php file has not been removed using the .htaccess file.

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

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

That should always do the trick.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »