CodeIgniter Forums
Loading Database result into Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Loading Database result into Class (/showthread.php?tid=74679)



Loading Database result into Class - illmaren - 10-23-2019

Hi,

i know that it works cause I saw how it worked but i'm not sure how to reproduce.

The following code shows how i try to Load the result of the database select into the object "Users" so that i get as result only the id of the Database.

Someone a Idea how to do this?
PHP Code:
<?php

class Users {
    public function __construct()
    {
    }

    public $id;

}

class 
home_model extends CI_Model
{
    private $db;

    public function __construct()
    {
        $this->db $this->load->database('default');
    }

    public function p(){
        $this->db $this->load->database('default'true);
        return $this->db->select('*')->get('auth_users')->custom_result_object(Users);
    }




RE: Loading Database result into Class - InsiteFX - 10-23-2019

Read:

CodeIgniter User Guide -> Generating Query Results -> Custom Result Objects


RE: Loading Database result into Class - illmaren - 10-23-2019

(10-23-2019, 05:56 PM)InsiteFX Wrote: Read:

CodeIgniter User Guide -> Generating Query Results -> Custom Result Objects

Yeah works partly how i want it.
thanks

Problem with this is if the field is not within the Class he return it anyway.
I want him to return only the fields within the Class


RE: Loading Database result into Class - InsiteFX - 10-24-2019

Sounds like you would need to write a custom select to do what you want,
just selecting the fields you need.