yii 修改dataProvider数组中CFormModel的值

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

所以另一个问题...我必须格式化一个通过CFormModel设置的数字,但问题是,如果我var_dump dataProvider,属性没有设置,但它们会出现在网站上。另外,如果我调用$dataProvider->value(其中value作为CFormModel扩展类中的公共参数存在),Yii会说该值没有设置(证明var_dump()是正确的)
1.怎么会这样?
1.如何通过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,其中,DataCherTransactions是另一个模块中的模型
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->数据,但我不能改变信息

rqdpfwrv

rqdpfwrv1#

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

public function afterSave() {
      //do modification here
      return parent::afterSave();
  }

相关问题