### 計算字段
_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;
}
// ...
}
```