[eluser]GonzaFY[/eluser]
Hi guys, I started to learn CodeIgniter and it is awesome! Congratulations =).
Then, I am trying to make a registration system but I am having some issues.
I read that I need make a library for simplify all the code so I have:
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Sistema_de_usuarios
{
// I use "Ingresar" to login
function Ingresar($usuario, $contrasenia) {
$CI =& get_instance();
$CI->load->library('session');
$CI->db->where('usuario', $usuario);
$CI->db->where('contrasenia', $contrasenia);
$consulta = $CI->db->get('miembros');
if($consulta->num_rows == 1)
{
// I store the info into sessions
$obtener = $consulta->row();
$data = array(
'usuario' => $usuario,
'conexion' => TRUE,
'nombre' => $obtener->nombre,
'apellido' => $obtener->apellido,
'rango' => $obtener->rango,
'correo' => $obtener->correo
);
$CI->session->set_userdata($data);
return true;
}
else {
return false;
}
}
// I use this function to check conection.
function Conexion() {
$CI =& get_instance();
return ($CI->session->all_userdata());
}
}
Now I wanna know how can I make a function to return all session.. then I call that function from my controller and automatically, for example, I write $username into my view and I see the name of the user.
I tried with this but doesn't work:
Code:
function Datos() {
$CI =& get_instance();
$datos['nombre'] = $CI->session->userdata('nombre');
$datos['apellido'] = $CI->session->userdata('apellido');
return $datos;
}
Thanks and sorry for the spanish =/ xD.