yii 修改dataProvider数组中CFormModel的值

cgyqldqp  于 2023-10-20  发布在  其他
关注(0)|答案(1)|浏览(251)

所以另一个问题...我必须格式化一个通过CFormModel设置的数字,但问题是,如果我var_dump dataProvider,属性没有设置,但它们会出现在网站上。另外,如果我调用$dataProvider->value(其中value作为CFormModel扩展类中的公共参数存在),Yii会说该值没有设置(证明var_dump()是正确的)
1.怎么会这样?
1.如何通过number_format()或与Yii相关的方法修改数字?

  1. CActiveDataProvider Object
  2. (
  3. [modelClass] => VouchersTransactions
  4. [model] => VouchersTransactions Object
  5. (
  6. [_new:CActiveRecord:private] =>
  7. [_attributes:CActiveRecord:private] => Array
  8. (
  9. )
  10. [_related:CActiveRecord:private] => Array
  11. (
  12. )
  13. [_c:CActiveRecord:private] =>
  14. [_pk:CActiveRecord:private] =>
  15. [_alias:CActiveRecord:private] => t
  16. [_errors:CModel:private] => Array
  17. (
  18. )
  19. [_validators:CModel:private] =>
  20. [_scenario:CModel:private] =>
  21. [_e:CComponent:private] =>
  22. [_m:CComponent:private] =>
  23. )
  24. [keyAttribute] =>
  25. [_criteria:CActiveDataProvider:private] => CDbCriteria Object
  26. (
  27. [select] => *
  28. [distinct] =>
  29. [condition] => user_id = 141
  30. [params] => Array
  31. (
  32. )
  33. [limit] => -1
  34. [offset] => -1
  35. [order] =>
  36. [group] =>
  37. [join] =>
  38. [having] =>
  39. [with] =>
  40. [alias] =>
  41. [together] =>
  42. [index] =>
  43. [scopes] =>
  44. [_e:CComponent:private] =>
  45. [_m:CComponent:private] =>
  46. )
  47. [_countCriteria:CActiveDataProvider:private] =>
  48. [_id:CDataProvider:private] => VouchersTransactions
  49. [_data:CDataProvider:private] =>
  50. [_keys:CDataProvider:private] =>
  51. [_totalItemCount:CDataProvider:private] =>
  52. [_sort:CDataProvider:private] =>
  53. [_pagination:CDataProvider:private] =>
  54. [_e:CComponent:private] =>
  55. [_m:CComponent:private] =>
  56. )

这是打印的dataProvider

  1. $dataProvider = new CActiveDataProvider('VouchersTransactions', array(
  2. 'criteria' => array(
  3. 'condition' => 'user_id = ' . Yii::app()->user->id,
  4. ),
  5. ));

这是dataProvider,其中,DataCherTransactions是另一个模块中的模型
L.E.**

  1. 0 => VouchersTransactions#1
  2. (
  3. [CActiveRecord:_new] => false
  4. [CActiveRecord:_attributes] => array
  5. (
  6. 'id' => '48'
  7. 'user_id' => '141'
  8. 'number_vouchers' => '1'
  9. 'voucher_value' => '0.0100'
  10. 'date_created' => '2014-07-11 10:06:22'
  11. )
  12. [CActiveRecord:_related] => array()
  13. [CActiveRecord:_c] => null
  14. [CActiveRecord:_pk] => '48'
  15. [CActiveRecord:_alias] => 't'
  16. [CModel:_errors] => array()
  17. [CModel:_validators] => null
  18. [CModel:_scenario] => 'update'
  19. [CComponent:_e] => null
  20. [CComponent:_m] => null
  21. )
  22. 1 => VouchersTransactions#2
  23. (
  24. [CActiveRecord:_new] => false
  25. [CActiveRecord:_attributes] => array
  26. (
  27. 'id' => '52'
  28. 'user_id' => '141'
  29. 'number_vouchers' => '1'
  30. 'voucher_value' => '10.0000'
  31. 'date_created' => '2014-07-11 10:15:06'
  32. )
  33. [CActiveRecord:_related] => array()
  34. [CActiveRecord:_c] => null
  35. [CActiveRecord:_pk] => '52'
  36. [CActiveRecord:_alias] => 't'
  37. [CModel:_errors] => array()
  38. [CModel:_validators] => null
  39. [CModel:_scenario] => 'update'
  40. [CComponent:_e] => null
  41. [CComponent:_m] => null
  42. )

这是我得到的,如果我转储$dataProvider->数据,但我不能改变信息

rqdpfwrv

rqdpfwrv1#

所以我在模型中使用Yii afterSearch()方法解决了这个问题。当你必须像这样修改值时,这是一个很好的方法。

  1. public function afterSave() {
  2. //do modification here
  3. return parent::afterSave();
  4. }

相关问题