Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.19 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Zend Framework Quickstart Model constructor
  2. public function __construct(array $options = null)
  3.     {
  4.         //if it is an array of options the call setOptions and apply those options
  5.         //so what? What Options
  6.         if (is_array($options)) {
  7.             $this->setOptions($options);
  8.         }
  9.     }
  10.  
  11.  public function setOptions(array $options)
  12.     {
  13.        //I can see this starts by getting all the class methods and return array()
  14.         $methods = get_class_methods($this);
  15.        //loop through the options and assign them to $method as setters?
  16.         foreach ($options as $key => $value) {
  17.             $method = 'set' . ucfirst($key);
  18.             if (in_array($method, $methods)) {
  19.                 $this->$method($value);
  20.             }
  21.         }
  22.         return $this;
  23.     }
  24.        
  25. { ["name"] => "RockyFord" }
  26.        
  27. setName("RockyFord");
  28.        
  29. foreach ($options as $key => $value) { // Loops through all options with Key,Value
  30.         $method = 'set' . ucfirst($key); // $method becomes 'setName' if key is 'name'
  31.         if (in_array($method, $methods)) { // Check if this method (setName) exists in this class
  32.             $this->$method($value); // Calls the method with the argument
  33.         }
  34.     }