Welcome Guest, Not a member yet? Register   Sign In
Migration - Model - __get
#1

Hi!!
I'm trying to migrate a project from codeigniter 1.7.2 to 2.x.x and later to 3.x.x.
How do I use the magic method __get in the model to access the value of attributes in the controller?
When trying to print the value of the attributes it returns as null. Only returns when attributes are public.
Tksss!!
example:

Model:
Code:
class Usuario extends CI_Model {

private id;
private nome;

function __construct() {
parent::__construct();
$this->load->model('mensagem');
}

public function __set($pname, $pvalue) {
$this->$pname = $pvalue;
}

public function __get($pname) {
if (property_exists($this, $pname)) {
return $this->$pname;
}
}
}
Controller:
Code:
class Homologacaoc extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('usuario');
}

public function index() {
$this->usuario->id = 123;
$this->usuario->nome = "teste";
var_dump($this->homologacao->id, $this->homologacao->nome);
}
}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB