CodeIgniter Forums

Full Version: use of $route in routes.php
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am having trouble understanding what I am doing wrong.  I have a routes.php in my config directory. It has these routes:
$route['default_controller'] = 'users/login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['registration'] = 'users/registration ';
$route['login'] = 'users/login';

In my views folder I have subdir called users with two files login.php and registration.php. Here is the bottom of the login.php:

Don't have an account? <a href="<?php echo base_url(); ?>registration">Register here</a></p>

When a user enters the site they type localhost/sub_crud/ and are brought to the login page. So far so good. 
My hope was that when a user clicks on the registration link above, then the URI would be localhost/sub_crud/registration, which it is, but would really view localhost/sub_crud/users/registration, which I guess is not working. I get Object Not Found from the browser when I click on the registration link. I am sure it is something basic that I am missing here. Any help for a beginner is appreciated. 
The default controller cannot be in a sub-directory.

If you need that you will have to redirect to it.
Thanks. That subdirectory, /users is actually a view. I do have two different controllers I am using. Users.php is for the login system and this has  3 different views, account, login and registration. Then I am also using grocery_crud which has its own controller called configuration.php and view.


The reason for two controllers is the use of two separate code sources, grocery_crud and codexworld's user authentication. Is there a better way to organize this? both controllers; configure and users are in the root of the app directory. Will I still need to redirect to get from one to the other? the controller configure and the view configure make up the grocery _crud part. The controller users and the views login, registration, and account make up the authentication part.
Try using a MY_Controller to do it.

Also look at the _remap() method.
I used the "view source" in chrome to see what the hyperlink is. 

this is how it appears in the source:
Don't have an account? <a href="<?php echo base_url(); ?>users/registration">Register here</a></p>

This is how it appears in the browser: 
Don't have an account? <a href="/sub_crud/users/registration]http://[::1]/sub_crud/users/registration">Register here</a></p>

I don't understand why it appears twice and the link is malformed. Anyway when I click on that link I get 

http://[::1]/sub_crud/users/registration 404 (Not Found)

I do have a users.php controller and it contains a registration method.
Well, I solved it, but I still don't know why. I just put index.php/ in front of the controller and now it works. I thought that I don't need to user index.php ? When I bring my app up from the chrome address bar I type "localhost/sub_crud", and that brings me directly to controller users and method login

Don't have an account? <a href="<?php echo base_url() ?>index.php/users/registration">Register here</a></p>
This means you haven't got proper rewrite rules, which is done outside of CI.