Welcome Guest, Not a member yet? Register   Sign In
use of $route in routes.php
#1

(This post was last modified: 11-04-2017, 06:33 AM by richb201.)

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>
</div>
</body

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. 
proof that an old dog can learn new tricks
Reply
#2

The default controller cannot be in a sub-directory.

If you need that you will have to redirect to it.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 11-04-2017, 12:39 PM by richb201.)

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.

1.Controllers
    2.Users.php
    2.Configure.php
3.Views
     4.Users
        5.Login.php
        5.Registration.php
        5.Account.php
     4.Configure.php

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.
proof that an old dog can learn new tricks
Reply
#4

Try using a MY_Controller to do it.

Also look at the _remap() method.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

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.
proof that an old dog can learn new tricks
Reply
#6

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>
proof that an old dog can learn new tricks
Reply
#7

This means you haven't got proper rewrite rules, which is done outside of CI.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB