Welcome Guest, Not a member yet? Register   Sign In
New to CI - View will not display
#1

[eluser]Unknown[/eluser]
Hello all,
I have this issue with a view that comes up as a 404 error. I am working on login authentication and I was doing really well until this problem. Basically what I do is get the information from a form, compare it to the DB and is there is a match I show a view. This view is the one the will not work. Here is the code:

My controller:

Code:
class Login extends CI_Controller {
    
    function index() {
        $data['main_content'] = 'login_form';
        $this->load->view('includes/template', $data);
    }
    
    function validate_credentials() {
        $this->load->model('authentication_model');
        $authentication = $this->authentication_model->validate();
        
        if($authentication) {
            $data = array(
                'username' => $this->input->post('username'),
                'authenticated' => true
            );
            
            $this->session->set_userdata($data);
            redirect('application/main');
        }
        else {
            $this->index();
        }
    }
}

The varianble $authentication does get set to true so I redirect to the application.php controller which looks like this:

Code:
class Main extends CI_Controller {
    function main () {
        $this->load->view('application_view');
    }
}

And the application_view.php which looks like this:

Code:
This is the members only area!

Any help will be greatly appreciated.
#2

[eluser]vitoco[/eluser]
The first problem that i see, it's that the redirection path it's wrong, your are telling CI redirect to controller "application" and method "main"

Code:
redirect('application/main');

but it must be controller "main" method "main"
Code:
redirect('main/main');

Second, the "main" function in "Main" controller it's the constructor, so it's called every time when you call a method of that class, and that can be a problem later, i think it will be better to change the function name to something different.
#3

[eluser]Unknown[/eluser]
[quote author="vitoco" date="1351456018"]The first problem that i see, it's that the redirection path it's wrong, your are telling CI redirect to controller "application" and method "main"

Code:
redirect('application/main');

but it must be controller "main" method "main"
Code:
redirect('main/main');

Second, the "main" function in "Main" controller it's the constructor, so it's called every time when you call a method of that class, and that can be a problem later, i think it will be better to change the function name to something different.
[/quote]

I love you.

I got mixed with the file name as it is still muddy to me how CI finds the files it needs. But that is for another post.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB