
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
None | size: 1.19 KB | hits: 17 | expires: Never
Zend Framework Quickstart Model constructor
public function __construct(array $options = null)
{
//if it is an array of options the call setOptions and apply those options
//so what? What Options
if (is_array($options)) {
$this->setOptions($options);
}
}
public function setOptions(array $options)
{
//I can see this starts by getting all the class methods and return array()
$methods = get_class_methods($this);
//loop through the options and assign them to $method as setters?
foreach ($options as $key => $value) {
$method = 'set' . ucfirst($key);
if (in_array($method, $methods)) {
$this->$method($value);
}
}
return $this;
}
{ ["name"] => "RockyFord" }
setName("RockyFord");
foreach ($options as $key => $value) { // Loops through all options with Key,Value
$method = 'set' . ucfirst($key); // $method becomes 'setName' if key is 'name'
if (in_array($method, $methods)) { // Check if this method (setName) exists in this class
$this->$method($value); // Calls the method with the argument
}
}