0
我有像以下这样的模型,其中我定义了一些静态变量(不在数据库表中),然后我试图获取这些变量,但它返回的是DB表中的变量。我想获取两个变量(静态变量以及DB表中的变量)。从yii CActiveRecord模型获取属性
型号
class Eforms extends CActiveRecord
{
public $emp_name;
public $current_status;
public $action_type;
public $action_type_extra;
public $common_value = array(
1 => 'Yes',
2 => 'No',
);
public $hr_only_value = array(
1 => 'IT',
2 => 'BOLD',
);
public static function model($className=__CLASS__)
{
return parent::model($className);
}
public function tableName()
{
return 'tbl_eforms';
}
public function rules()
{
return array(
array('form_id', 'required'),
array('form_id, user_id', 'numerical', 'integerOnly'=>true),
array('name_in_form', 'length', 'max'=>500),
array('pdf_name', 'length', 'max'=>1000),
array('emp_name, current_status, action_type, action_type_extra', 'required', 'on'=>'form1'),
array('emp_name, current_status, action_type, action_type_extra','safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, form_id, user_id, name_in_form, email_recipients, pdf_name, created_on', 'safe', 'on'=>'search'),
);
}
................
...............
控制器:
public function actionIndex()
{
$model=new Eforms;
var_dump($model->attributes);exit;
}
如果我改变了CActiveRecord
与CFormModel
在它返回的唯一静态变量不是DB相关的一个。
请解释更好您的问题(与/计算)变种。如果用同比CFormModel你没有得到变量相关db这是正确的行为 – scaisEdge
@scaisEdge,但我需要两个属性(变量涉及到DB以及其他变量与数据库无关) – DS9
所以问题是我怎么能这两个变量? – DS9