Nope, Phalcon doesn't create the accessors for you, $robot->id = 2
is not same as $robot->setId(2)
, this is really related PHP OO and not Phalcon.
if you have public function setId($id) { ... }
for protected property (class variable), you then have to set that property like $robot->setId(2)
.
In the Phalcon examples, public class variables is used, or you can use protected class variables with magic method accessors. See __get()
and __set()
here : https://php.net/manual/en/language.oop5.magic.php
Here is my set magic method.
/*
* Checks if property exists
* Changes $this->camelCase to $this->camel_case, due to my DB naming convention
* omited this on my __get example above
*/
public function __set($name, $value)
{
if (!property_exists($this, $name)) {
$name = preg_replace_callback('/[A-Z]/', function($matches) {
return '_' . strtolower($matches[0]);
}, $name);
}
$this->$name = $value;
}