Loading page gives an error in CodeIgniter
When I login, it gives me "error page not found". It's not loading the controller function.
This is my view file:
<form name="loginform" action="welcome/login" method="post">
Enter User Name:
<input type="text" name="uname">
Enter Password
<input type="password" name="pass">
<input type="submit" name="login" value="Login">
This is my login controller file:
class Login extends Controller {
function Login()
{
parent::Controller();
}
function login()
{
$this->load->view('welcome_message');
}
}
开发者_如何学Python
This is my welcome controller file:
class Welcome extends Controller {
function Welcome()
{
parent::Controller();
}
function index()
{
$this->load->model('Loginmodel');
$this->load->view('welcome_message');
}
public function login()
{
$this->load->model('Loginmodel','login');
$info = $this->logn->login();
$this->load->view('welcome_message',$info);
}
}
Can you give me any idea what is wrong?
The code you provided seems fine, so I would guess it has to do with this:
<form name="loginform" action="welcome/login" method="post">
The path is relative, which is only going to work if there are no url segments present. If the current URL is /hello/world
, you will end up posting to /hello/world/welcome/login
Try a full URL or absolute path. Example:
<form name="loginform" action="/welcome/login" method="post">
<!-- ^^^ Note the leading forward slash -->
Or use base_url()
for the full url:
<form action="<?php echo base_url(); ?>welcome/login">
You may also be interested in the form_open()
function which will do this automatically.
<?php echo form_open('welcome/login'); ?>
The only other thing I can see would have to do with whatever $this->login->login();
does. If you can confirm what your URL actually is when you see the "page not found" error, that would be a great help.
精彩评论