Welcome Guest, Not a member yet? Register   Sign In
Model / Entities relation
#3

(This post was last modified: 02-22-2019, 07:16 AM by keulu.)

(02-22-2019, 03:10 AM)puschie Wrote: you need to use the magic setter/getter in your entity to use _options

ok, i will give a try, thx for the advise Smile


Edit :

Nope... that doesn't work as wanted...

Entities/User.php

PHP Code:
<?php namespace App\Entities;

use 
CodeIgniter\Entity;
use 
CodeIgniter\I18n\Time;

class 
User extends Entity
{
    protected 
$id;
    protected 
$firstname;
    protected 
$lastname;
    protected 
$username;
    protected 
$email;
    protected 
$password;
    protected 
$created_at;
    protected 
$updated_at;
    protected 
$deleted;
    protected 
$deleted_at;

    protected 
$_options = [
        
'datamap' => [
            
'username' => 'full_name',
        ],
        
'dates'   => [
            
'created_at',
            
'updated_at',
            
'deleted_at',
        ],
        
'casts'   => [
            
'deleted' => 'boolean',
        ],
    ];

    public function 
__get(string $key)
    {
        if (
property_exists($this$key))
        {
            return 
$this->$key;
        }
    }

    public function 
__set(string $key$value NULL)
    {
        if (
property_exists($this$key))
        {
            
$this->$key $value;
        }
    }


result in Json

Code:
{
  "success": true,
  "message": "",
  "data": [
    {},
    {}
  ]
}

So the model find 2 Users, but can't access to property :/
Reply


Messages In This Thread
Model / Entities relation - by keulu - 02-20-2019, 02:45 AM
RE: Model / Entities relation - by puschie - 02-22-2019, 03:10 AM
RE: Model / Entities relation - by keulu - 02-22-2019, 07:09 AM
RE: Model / Entities relation - by puschie - 02-25-2019, 07:17 AM
RE: Model / Entities relation - by keulu - 02-26-2019, 11:31 AM
RE: Model / Entities relation - by keulu - 02-26-2019, 01:41 PM
RE: Model / Entities relation - by keulu - 02-27-2019, 11:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB