### 计算字段
_volume该字段在数据库中不存在,当表单提交length,width,height字段的时候,通过实例化Room类调用getVolume()方法就可以计算出结果. 该方法还可以用于从数据库取出这3个属性 as _volume 字段来使用
```
class Room extends \yii\db\ActiveRecord
{
private $_volume;
public function setVolume($volume)
{
$this->_volume = (float) $volume;
}
public function getVolume()
{
if (empty($this->length) || empty($this->width) || empty($this->height)) {
return null;
}
if ($this->_volume === null) {
$this->setVolume(
$this->length * $this->width * $this->height
);
}
return $this->_volume;
}
// ...
}
```
