I am fairly new to CI and I am working my way through a project using it.
I am using CI 2.1.2 DataMapper 1.8.2.1.
I am trying to post a login form to http://www.example.com/userauthcontroller/login I am able to hit the function and it authenticates as it should. Mainly using the DataMapper examples and code.
Userauthcontroller.php:
public function login(){
$params = $this->input->post();
$url = $params['url'];
$loginId = $params['loginid'];
$password = $params['loginpass'];
$u = new User();
$u->username = $loginId;
$u->pass_word =$password;
if($u->login()){
$confirmedUser = $u->get_where(array('id' => $u->id));
$CI =& get_instance();
$CI->session->set_userdata(array('currentuser' => $confirmedUser));
//print_r($CI->session->userdata('currentuser'); // works
//die();
//tried this too
//$this->session->set_userdata(array('currentuser' => $confirmedUser));
redirect($url);
}else{
echo '<p>' . $u->error->login . '</p>';
}
}
When I redirect to the welcome controller I can not find the currentuser in the session.
welcome.php:
function index(){
$data['site_title'] = "My Site Title";
$data['view_file'] = "layout_views/home_view";
$CI =& get_instance();
$user = $CI->session->userdata('currentuser');
$data['currentuser'] = $user;
print_r($user);
print("<BR/>");
print_r($data);
die();
//If I let this continue into my view $currentuser is not available.
$this->load->view('index_view', $data);
}
home_view.php:
<p><? echo $currentuser ?></p> <!-- this does not print -->
<p><? echo $site_title ?></p> <!-- this prints -->
application/config/autoload.php: (Relevant entries that I know of)
$autoload['libraries'] = array('database', 'datamapper', 'session');
$autoload['packages'] = array(APPPATH.'third_party/datamapper');
I have done a bit of searching on this ... and I even checked for spelling errors.
Any suggestions would be appreciated.
If more information is needed I will be checking back here frequently.
Thanks