所以另一个问题…我必须格式化一个数字,通过CFormModel设置,但事情是,如果我var_dump的数据提供程序,属性没有设置,但它们出现在网站上。此外,如果我调用$dataProvider->value(其中值作为CFormModel扩展类中的公共参数存在)Yii说值未设置(证明var_dump()是正确的)
- 如何来吗?
-
如何通过number_format()或与yii相关的方法修改号码?
CActiveDataProvider Object ( [modelClass] => VouchersTransactions [model] => VouchersTransactions Object ( [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => [_e:CComponent:private] => [_m:CComponent:private] => ) [keyAttribute] => [_criteria:CActiveDataProvider:private] => CDbCriteria Object ( [select] => * [distinct] => [condition] => user_id = 141 [params] => Array ( ) [limit] => -1 [offset] => -1 [order] => [group] => [join] => [having] => [with] => [alias] => [together] => [index] => [scopes] => [_e:CComponent:private] => [_m:CComponent:private] => ) [_countCriteria:CActiveDataProvider:private] => [_id:CDataProvider:private] => VouchersTransactions [_data:CDataProvider:private] => [_keys:CDataProvider:private] => [_totalItemCount:CDataProvider:private] => [_sort:CDataProvider:private] => [_pagination:CDataProvider:private] => [_e:CComponent:private] => [_m:CComponent:private] => )
这是打印的数据提供程序
$dataProvider = new CActiveDataProvider('VouchersTransactions', array(
'criteria' => array(
'condition' => 'user_id = ' . Yii::app()->user->id,
),
));
这是数据提供者,其中VoucherTransactions是另一个模块中的模型
L.E.
0 => VouchersTransactions#1
(
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array
(
'id' => '48'
'user_id' => '141'
'number_vouchers' => '1'
'voucher_value' => '0.0100'
'date_created' => '2014-07-11 10:06:22'
)
[CActiveRecord:_related] => array()
[CActiveRecord:_c] => null
[CActiveRecord:_pk] => '48'
[CActiveRecord:_alias] => 't'
[CModel:_errors] => array()
[CModel:_validators] => null
[CModel:_scenario] => 'update'
[CComponent:_e] => null
[CComponent:_m] => null
)
1 => VouchersTransactions#2
(
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array
(
'id' => '52'
'user_id' => '141'
'number_vouchers' => '1'
'voucher_value' => '10.0000'
'date_created' => '2014-07-11 10:15:06'
)
[CActiveRecord:_related] => array()
[CActiveRecord:_c] => null
[CActiveRecord:_pk] => '52'
[CActiveRecord:_alias] => 't'
[CModel:_errors] => array()
[CModel:_validators] => null
[CModel:_scenario] => 'update'
[CComponent:_e] => null
[CComponent:_m] => null
)
这是我得到的如果我转储$dataProvider->data但我不能改变那里的信息
所以我使用模型中的Yii afterSearch()方法解决了这个问题。当你必须修改这样的值时,这是一个很好的方法。
public function afterSave() {
//do modification here
return parent::afterSave();
}
希望这对其他人也有帮助!
阿瑞斯。