Welcome Guest, Not a member yet? Register   Sign In
Making a registration system
#1

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

[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;
}
#3

[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?
^^!
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB