Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14348

Problem with returned from the database in class

$
0
0
Hello. CodeIgniter 3.1.3 problem in the following

class User_lib {
protected $customer_id;
protected $email;
protected $firstname;
protected $date_added;
}

model
public function get_customer()
{
$this->db->from('stels_customer');
$this->db->where('stels_customer.customer_id', 1);
$query = $this->db->get();
return $query->row(0, 'User_lib');
}

controller
public function index()
{
$this->load->model('user_model');
$this->load->library('user_lib');
var_dump($this->user_lib);
$user = $this->user_model->get_customer();
var_dump($user);
}

results
D:\Ampps\www\igniter\application\controllers\Welcome.php:26:
object(User_lib)[17]
protected 'customer_id' => null
protected 'email' => null
protected 'firstname' => null
protected 'date_added' => null

D:\Ampps\www\igniter\application\controllers\Welcome.php:30:
object(User_lib)[20]
protected 'customer_id' => string '1' (length=1)
protected 'email' => string 'test@test.ua' (length=16)
protected 'firstname' => string 'Имя' (length=6)
protected 'date_added' => string '2017-02-07 08:48:10' (length=19)

Why are set value to non-public properties.

In guide:
The object will have all values returned from the database set as properties. If these have been declared and are non-public then you should provide a __set() method to allow them to be set.

Sorry for my English

Viewing all articles
Browse latest Browse all 14348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>