Pawan Pawan - 3 months ago 49
PHP Question

Yii2: Adding php sprintf function to format value in gridview

I am trying to add leading zeros to a number to be shown in gridview.
I am trying this code, but it is throwing error like:

Getting unknown property: app\models\OpdTestBill::0000

The code I am using is like this:


What is the proper syntax to achieve this?



[ 'attribute'=>'dhanwantri_bill_number',

Here too I am getting the error:

Unknown format type: 0000

throw new InvalidParamException("Unknown format type: $format")


OK I found the solution, anyone having problem can find it useful.

'value'=>function($model) {
 return sprintf('%04d',$model->dhanwantri_bill_number);