• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Relation entity

#1
Hello! I am from Argentina. Sorry for my bad English.   

I have a simple entity:

PHP Code:
<?php

namespace App\Entities;

class 
Usuario {

    protected $id;
    protected $nombre;
    protected $apellido;
    protected $fecha_nacimiento;
    protected $dni;
    protected $email;
    protected $imagen;
    protected $id_puesto;
    protected $id_area;
    protected $id_sector;
    protected $session_id;
    protected $is_su;
    protected $limitar_cajas;
    protected $habilitado;
    protected $password;
    protected $defecto;
    protected $fecha_alta;

    public function __set(string $key$value null) {
        $method 'set' ucwords($key);
        if (method_exists($this$method)) {
            $this->$method($value);
        } else if (isset($this->$key)) {
            $this->$key $value;
        }
    }

    public function __get(string $key) {
        $method 'get' ucwords($key);
        if (method_exists($this$method)) {
            return $this->$method();
        } else if (isset($this->$key)) {
            return $this->$key;
        }
    }



This entity is associated with a user model.

My question is: How do I communicate, for example, id_area with your table? The desired result would be:

$user->area->name or $user->area->id.

Thanks.
Reply

#2
CodeIgniter does not have built-in Object Relation Mapping so you will either need to do this yourself or use a module that adds that functionality (https://github.com/tattersoftware/codeig...-relations, https://forum.codeigniter.com/thread-748...#pid369959, https://github.com/yidas/codeigniter-model).
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.