Hello,
Here is my situation. I am using find()
to look for a record in a db and I pass it to the ReflectionObject
$result = $this->find($id);
return $this->getResultObjects($result);
...
protected function getResultObjects($result)
{
foreach ($result as $row) {
$this->users->setProperty($row);
}
}
...
public function setProperty($object)
{
$reflection = new \ReflectionObject($object);
foreach ($reflection->getProperties() as $property) {
$property->setAccessible(TRUE);
$key = '_' . $property->getName();
$this->$key = $property->getValue($object);
}
return $this;
}
if i leave this as is then i get Phalcon\Exception: Invalid __set property _di
that is because i don't have a protected var $_di
my model has only:
protected $_id;
protected $_name;
protected $_email;
protected $_password;
but if I var_dump($reflection->getProperties());
i get a lot more properties (see below) and i only want to pass to the ReflectionObject
the properties that my model has
Is there a way to only grab the properties I need from the query result and ignore the rest of them?
edit: i know i could just type the name of the properties i want, but that defits the purpose of my getResultObjects()
method, that automatically sets the class properties
array (size=18)
0 => &
object(ReflectionProperty)[128]
public 'name' => string 'di' (length=2)
public 'class' => string 'Application\Models\Users' (length=24)
1 => &
object(ReflectionProperty)[127]
public 'name' => string 'usersEntity' (length=11)
public 'class' => string 'Application\Models\Users' (length=24)
2 => &
object(ReflectionProperty)[126]
public 'name' => string '_dependencyInjector' (length=19)
public 'class' => string 'Phalcon\Mvc\Model' (length=17)
3 => &
object(ReflectionProperty)[125]
public 'name' => string '_modelsManager' (length=14)
public 'class' => string 'Phalcon\Mvc\Model' (length=17)
...
...
... i want only the ones below
15 => &
object(ReflectionProperty)[143]
public 'name' => string 'id' (length=2)
public 'class' => string 'Application\Models\Users' (length=24)
16 => &
object(ReflectionProperty)[144]
public 'name' => string 'name' (length=4)
public 'class' => string 'Application\Models\Users' (length=24)
17 => &
object(ReflectionProperty)[145]
public 'name' => string 'email' (length=5)
public 'class' => string 'Application\Models\Users' (length=24)
18 => &
object(ReflectionProperty)[146]
public 'name' => string 'password' (length=8)
public 'class' => string 'Application\Models\Users' (length=24)