Welcome Guest, Not a member yet? Register   Sign In
Loading Database result into Class
#1

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);
    }

Reply
#2

Read:

CodeIgniter User Guide -> Generating Query Results -> Custom Result Objects
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(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
Reply
#4

Sounds like you would need to write a custom select to do what you want,
just selecting the fields you need.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB