Reputation: 14250
I am having trouble trying to pass an valuable after the user fail the authorization. I would like to pass $error to the welcome controller but not sure how. Please help. Thank you.
private function _user_check()
{
//after form validation, I pass username and password to the model
$this->load->model('user_query');
$result=$this->user_query->query($this->input->post('username'),$this->
input->post('password'));
if($result)
{
redirect('main');
}else{
// I am not sure how to pass this error message to my welcome controller
$data['error']='Please check your username or password';
redirect('welcome');
}
}
Upvotes: 0
Views: 64
Reputation: 580
In the redirect function, you aren't providing a full URL, so CI is going to treat the parameter as an URI segments to the controller.
Knowing this, you could have something like:
redirect('welcome/error/error_user_pass');
and have your "error_user_pass" that is being passed reference error constants defined in your CI project.
Maybe something like this in your application/config/constants.php file:
define('error_user_pass', 'incorrect user or password, please check yo self!');
Then in your 'welcome' controller having something like this:
class Welcome extends CI_Controller {
public function error(){
$errors = func_get_args();
foreach( $errors as $error ){
//echo error, or save it, or whatev
}
}
}
Upvotes: 2