开发者

Stumped by CodeIgniter controllers found but not found

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:

$route['engineering-resources/login'] = "resources/login";

Even when I get to it this way, my form action isn't found. Here is my form:

<?php 
    echo form_open('resources/login/validate_credentials'); //folder/controller/method.  I think this is where my problem is
    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:

class Login extends Controller {

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

    }

    function validate_credentials()
    {       
        $this->load->model('login/membership_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/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?

Here is main.php

<?php $this->load->view('includes/header.php'); ?>

<?php $this->load->view('includes/nav.php'); ?>

<?php $this->load->view($main_content); 开发者_如何学C?>

<?php $this->load->view('includes/footer.php'); ?>


$route['engineering-resources/login'] = "resources/login";

This does not route to engineering-resources/login/validate_credentials to resources/login/validate_credentials

You should have something like this:

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

One more thing is that if you are using routes, you should use the routes from your views too..

echo form_open('engineering-resources/login/validate_credentials');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜