所以另一个问题......我必须格式化一个通过CFormModel设置的数字,但事实是,如果我var_dump dataProvider,属性没有设置,但它们出现在网站上。另外,如果我调用$ dataProvider-> value(其中value作为CFormModel扩展类中的公共参数存在)Yii sais没有设置该值(证明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
$dataProvider = new CActiveDataProvider('VouchersTransactions', array(
'criteria' => array(
'condition' => 'user_id = ' . Yii::app()->user->id,
),
));
这是dataProvider,其中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->数据但我无法改变信息,这就是我得到的
答案 0 :(得分:0)
所以我使用模型中的Yii afterSearch()方法解决了这个问题。必须修改这样的值时使用的好方法。
public function afterSave() {
//do modification here
return parent::afterSave();
}
希望这对其他人也有帮助!
顷。