Reputation:
Here i'm creating a login system. Once the user is verified the controller redirects the page to home
.php.
There are 2 pages here login_registration.php and home.php
login_registration.php consists login and registration form from here the user is redirected to home.php. both the files are in path C:\wamp\www\CI-Project_1\application\views\login
The issue is it show 404 Page Not Found
when redirected.
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
//LOAD MODELS HERE
$this->load->model('Login_model');
}
public function index(){
$this->load->view('login/login_registration.php');
}
function login_user(){
$login_btn = $this->input->post('login_btn');
if($login_btn == TRUE){
$arr['login'] = array(
'username'=>$this->input->post('username'),
'password'=>$this->input->post('password')
);
$query = $this->Login_model->users_login($arr);
if($query->num_rows() > 0 && $query->num_rows() == 1){
$this->load->library('session');
$this->session->set_userdata($arr['login']);
redirect('login/home.php', 'location');
}
else
{
$this->index();
}
}
else
{
$this->index();
}
}
}
Upvotes: 1
Views: 278
Reputation: 248
For redirect and $this->load->view
, don't use .php
.
Use something like this:
redirect('login/home', 'location');
Upvotes: 0
Reputation: 1423
You have to mention the name of your controller and method name where you want to redirect something like this
redirect('controllername/methodname');
Upvotes: 1
Reputation: 137
To redirect on any function in CI can use redirect('controller n_name/function_name','refresh');
Upvotes: 0
Reputation: 708
Why you going to redirect if you want to call any method from a controller then you can redirect like that:
public function home(){
$this->load->view('login/home.php');
}
redirect('login/home', 'location');
But I think you don't need to redirect you can simply load view file just like you already load your registration view. So you just load view Instead of redirect..
$this->load->view('login/home.php');
Upvotes: 0
Reputation: 170
According to codeigniter views documentation
The .php file extension does not need to be specified unless you use something other than .php.
So, the correct code is as follow:
$this->load->view('login/login_registration');
Also you are not using the redirect function correctly, as i don't see any home function inside login controller. If you somehow have home function inside login controller then why are you using .php after function name?
Check the codeigniter redirect documentation for more info.
Upvotes: 2
Reputation: 2168
Try this,
class Login extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
//LOAD MODELS HERE
$this->load->model('Login_model');
}
public function index(){
$this->load->view('login/login_registration.php');
}
public function home(){
$this->load->view('login/home.php');
}
function login_user(){
$login_btn = $this->input->post('login_btn');
if($login_btn == TRUE){
$arr['login'] = array(
'username'=>$this->input->post('username'),
'password'=>$this->input->post('password')
);
$query = $this->Login_model->users_login($arr);
if($query->num_rows() > 0 && $query->num_rows() == 1){
$this->load->library('session');
$this->session->set_userdata($arr['login']);
redirect('login/home', 'location');
}
else
{
$this->index();
}
}
else
{
$this->index();
}
}
}
Upvotes: 0