4
このトピックの基礎として、ZFクイックスタートcreate modelを使用しています。
この文脈で__constructとsetOptions()メソッドが何をしているのかを正確に理解したいと思います。
私が何回何度叩いても、私はこれらの2つの方法が何をしているのか分かりません。Zend Framework Quickstart Modelコンストラクタ
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;
}
私は本当に(setOptonsに迷子に)、私はそれを達成しようとしているかを把握することはできません。私はそれがいくつかの行動を抽象化していることを理解しています、私はちょうど何を推測することはできません。
私が言うことができる限り、これはちょうどそんなに「なんで!」。私はそれが重要となるかもしれないので、それを理解したいと思います。
ありがとう、私は突然すべてを理解しています。これにより、get *またはset *を明示的に呼び出す代わりに配列を渡すことができます – RockyFord