我有一个附加到模型的行为,该行为应该根据模型的某些属性而有所不同。例子:
class Airplane extends AppModel {
var $actsAs = array('Flying');
}
class FlyingBehavior extends ModelBehavior {
function flightTime(&$Model, $distance) {
return $distance / $this->speed;
}
}
最初我以为我将其设置为
class Airplane extends AppModel {
var $actsAs = array('Flying' =>
array('speed' => SOMENUM)
);
}
class FlyingBehavior extends ModelBehavior {
function setup(&$Model, $settings) {
$this->speed = $settings['speed'];
}
function flightTime(&$Model, $distance) {
return $distance / $this->speed;
}
}
但我不知道如何进行这项工作,因为我需要speed
从每条Airplane
记录中获取列。我该怎么做?