How to get the id from a codeigniter driver

0

I'm modifying my controller to get the id and send it to the view that has the role, the roles are handled directly from the table default_users

public function sendNew($msg = null)
{
       /*funcion para extrar el usuario logeado */
    $resu = $this->session->userdata('group_id');
  if ($resu == '100') {
      $this->template
    ->build('send');
  } else {
      $this->template
    ->build('sendusers');
  }
}

in the controller always enters the else, I did it with a query to the database which is the following

mysql_connect("localhost","root","imagina7192");
    mysql_select_db("intranet_gana");
  $cons = "SELECT * FROM 'default_users' WHERE 'group_id' = 100";

    $resu=mysql_query($cons);

    $resu = $this->session->userdata('group_id');
  if ($resu == '100') {
      $this->template
    ->build('send');
  } else {
      $this->template
    ->build('sendusers');
  }

The group_id is where the role is handled, where 100 is admin and 1 is a user without permission to see the view

Grace beforehand

    
asked by Edison Sarmiento 05.04.2018 в 01:54
source

1 answer

0

I do not understand what you are trying to do, the connections in codeigniter are very different, it has its own way of making queries if both roll and in a simpler way and for that there are models. Codeigniter has its own database file inside the config folder in which you enter your connection data at base de datos .

Controller:

public function obtenerServicios()
{
    //En la variable data guardo lo que me regrese el modelo
    $data['datos'] = $this->Inicio_model->obtenerServicios();

    //Al cargar una vista paso la variable data para mostrar posteriormente en la vista
    $this->load->view('main',$data);
}

Model:

public function obtenerServicios()
{
    $this->db->select('s.*,u.nombre as usuario');
    $this->db->from('servicios s');
    $this->db->join('usuarios u', 's.id_user = u.id');

    //realizo la consulta
    $aResult = $this->db->get();
    if(!$aResult->num_rows() == 1)
    {
        return false;
    }
    //retorno el arreglo de datos que me regresa la consulta
    return $aResult->result_array();
}

It is such a simple way to perform queries to the database that you are complicating all the work.

    
answered by 02.06.2018 в 06:06