Welcome Guest, Not a member yet? Register   Sign In
Custom Result Objects & Setter
#5

See https://www.php.net/manual/en/mysqli-res...object.php
Mysqli creates an object a little differently. As Reflection?
Props id, user_id, title, is_read not calling __set(). body, created_at run __set(). What did I say wrong?

PHP Code:
    // Setter
    public function __set($name$value)
    {
        echo $name PHP_EOL;

        $this->{$name} = $value;

        return $this;
    }
    
    
// Contains row: id, user_id, title, is_read, body, created_at
    $notify model(NotificationModel::class)->builder()->limit(1)->get()->getCustomResultObject(Notify::class);

    // Output
    body created_at

 
array:[
  0 
=> App\Controllers\Notify {#199 ▼
    #id: "5"
    #user_id: "1"
    #title: "New Message"
    #is_read: "yes"
    +"body""New post created!"
    +"created_at""2023-11-01 20:18:43"
  }

Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply


Messages In This Thread
Custom Result Objects & Setter - by Fabien72 - 11-03-2023, 12:49 PM
RE: Custom Result Objects & Setter - by kenjis - 11-03-2023, 04:28 PM
RE: Custom Result Objects & Setter - by ozornick - 11-03-2023, 10:26 PM
RE: Custom Result Objects & Setter - by kenjis - 11-03-2023, 10:41 PM
RE: Custom Result Objects & Setter - by ozornick - 11-04-2023, 02:24 AM
RE: Custom Result Objects & Setter - by Fabien72 - 11-05-2023, 09:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB