David Brooks David Brooks - 4 months ago 10
PHP Question

Code Igniter not running the method in the controller

I have a form in a view called login_view that I would like to target a function in the Login controller.

For my form in login_view I have

echo form_open('/Login/validate_credentials');


In my Login.php controller I have:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller{

function __construct()
{
parent::__construct();
}

public function validate_credentials(){
$this->load->view('welcome2');
}
}
?>


When I submit the form from the browser, instead of loading the welcome2 view like I expect, it tries to load the URL of:

localhost/project/Login/validate_credentials


and I just see the default page for WAMP.

It's my first day in Code Igniter so I'm sure the answer is simple.

Answer

Just replace your controller construct by this:

 public function __construct()
 {
    parent::__construct();
    $this->load->helper(array('url','text','html','form','string'));
}