Yii2 使用七 Model添加非表字段属性
<?php //model class User extends CActiveRecord { public function getFullname() { if ($this->first_name && $this->last_name) { return $this->first_name . ' ' . $this->last_name; } return 'Unknown'; } } ?> //view <span><?php echo $user->fullname ?></span>或 <?=$user->getFullname()?>