CodeIgniter Forums
Controller not found except by route - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Controller not found except by route (/thread-37358.html)



Controller not found except by route - El Forum - 01-06-2011

[eluser]sehummel[/eluser]
OK, I admit it. I'm a CI newbie. I'm doing something really basic wrong and I've been at it for a couple of hours and can't find my error.

I have a controller called login. It's in the resources folder in my controllers folder. It loads a view called login_form. But for the life of me it will not load if I go to domain.com/resources/login or domain.com/resources/index. But I can get to it via a route:

Code:
$route['engineering-resources/login'] = "resources/login";
Even when I get to it this way, my form action isn't found. Here is my form:

Code:
<?php
    echo form_open('resources/login/validate_credentials');  // resources folder/login controller/validate_credentials method
    echo form_input('username', 'Username');
    echo form_password('password', 'Password');
    echo form_submit('submit', 'Login');
    echo anchor('login/signup', 'Create Account');
    echo form_close();
    ?>

The path is my resources folder in my controllers folder, and the controller is the login controller using the validate_credentials method. Here is the pertinent part of my login controller:

Code:
class Login extends Controller {

    function index()
    {
        $data['title'] = 'Engineering Resources | Login';
        $data['main_content'] = 'resources/login_form';  // resources folder/login form view
        $this->load->view('templates/main.php', $data);

    }

    function validate_credentials()
    {      
        $this->load->model('login/membership_model');  // login folder, membership_model model
        $query = $this->membership_model->validate();

        if($query) // if the user's credentials validated...
        {
            $data = array(
                'username' => $this->input->post('username'),
                'is_logged_in' => true
            );
            $this->session->set_userdata($data);
            redirect('resources/login/members_area');
        }
        else // incorrect username or password
        {
            $this->index();
        }
    }

The index function works when I use the route, but not when I use the above domain.com paths. I assume that is why it cannot find the validate_credentials method. What am I doing wrong?


Controller not found except by route - El Forum - 01-06-2011

[eluser]sehummel[/eluser]
I got my answer: I needed:

Code:
$route['engineering-resources/login/(\S*)'] = "resources/login/$1";

But what do the
Code:
(\S*)
and
Code:
$1
do?


Controller not found except by route - El Forum - 01-06-2011

[eluser]Cristian Gilè[/eluser]
Hi sehummel,
Quote:I have a controller called login. It’s in the resources folder in my controllers folder. It loads a view called login_form. But for the life of me it will not load if I go to domain.com/resources/login or domain.com/resources/index.
You go to to domain.com/resources/login without index.php. Do you use .htaccess? If not, it should be domain.com/index.php/resources/login.

Quote:The index function works when I use the route, but not when I use the above domain.com paths. I assume that is why it cannot find the validate_credentials method. What am I doing wrong?

Again, try domain.com/index.php/resources/login


Quote:But what do the
Code:
(\S*)

and
Code:
$1

do?

(\S*) is a regex matching non-whitespace character.
$1 is the remapped variable from the route (what has been passed as (\S*))


Cristian Gilè