Issue with URI routing so links doesn't work with CodeIgniter Issue with URI routing so links doesn't work with CodeIgniter codeigniter codeigniter

Issue with URI routing so links doesn't work with CodeIgniter


just call controller and method

<li><a href="login/login">Inloggen</a></li>

If not works

<li><a href="index.php/login/login">Inloggen</a></li>

try this


When you extend a class that has a constructor, you need to call that constructor from the class you are extending it from... ie

class Controller_name extends CI_Controller {public function __construct(){    parent::__construct(); // Call the CI_Controller __construct();}

Note that the __ is actually two underscores but appears a a single line on here.

With your Routes

routes.php

$route['default_controller'] ='pages/view';$route['login'] = 'login/view/login';

Remember that a CI URL is of the form domainname.com/controller/method

The default_controller is where the browser will be redirected to if you do not supply the controller/method ie - just domainname.com. With your default controller route, you will be redirecting to your pages controller and accessing the view method. Going by your code that should be fine.

Your login route should also be fine if you access domainname.com/login as your url - this will be sent to your login controller, view method and passing in login as the page name.

home.php

 <ul>   <li><a href="home.php">Homepagina</a></li>   <li><a href="about.php">Over</a></li>   <li><a href="<?php echo site_url('login/login'); ?>">Inloggen</a></li>   <li><a href="register.php">Registreren</a></li>   <li><a href="<?php echo site_url('myprofile/myuserprofile'); ?>">Profiel</a></li>   <li><a href="matches.php">Matches</a></li>   <li><a href="config.php">Config</a></li> </ul>

With your link to home.php, you might want to create a controller called Home.php and define the index() method. So change

<a href="home.php">Homepagina</a>

to

<a href="home">Homepagina</a>

The link then becomes domainname.com/home - which points to your home controller and it's index method.

Then we come to this

<a href="<?php echo site_url('login/login');

This will create domainname.com/login/login. Your login route is only looking for domainname.com/login. So the current link domainname.com/login/login is looking for a Controller called login with a method called login.

Your link with myprofile/myuserprofile will be looking for a controller called myprofile and a method called myuserprofile. There is nothing in your routes.php to deal with this. So if that is not working, it's nothing to do with the routes.

So this is all pointing back to you (possibly) not having defined the __construct methods as I discussed at the beginning.


<li><a href="index.php/login/login">Inloggen</a></li>

if it works you can remove index.php.follow this documentation to remove index page