CodeIgniter Forums
Making a registration system - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Making a registration system (/thread-57040.html)



Making a registration system - El Forum - 02-09-2013

[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.


Making a registration system - El Forum - 02-09-2013

[eluser]InsiteFX[/eluser]
Try this:
Code:
function Datos()
{
   $CI =& get_instance();

   $datos = array(
        'nombre'   => $CI->session->userdata('nombre'),
        'apellido' => $CI->session->userdata('apellido')
    );

    return $datos;
}



Making a registration system - El Forum - 02-09-2013

[eluser]GonzaFY[/eluser]
[quote author="InsiteFX" date="1360477936"]Try this:
Code:
function Datos()
{
   $CI =& get_instance();

   $datos = array(
        'nombre'   => $CI->session->userdata('nombre'),
        'apellido' => $CI->session->userdata('apellido')
    );

    return $datos;
}
[/quote]

Works perfectly! Thanks Wink...

What is better? Make my registration system in a model or in a library?
^^!


Making a registration system - El Forum - 02-10-2013

[eluser]InsiteFX[/eluser]
I would make it into a library and create a model for handling the database records.

This way your library can call the model methods and pass the data back to your Controller.