phone number format

Is there a way to format 0000000000 to (000) 000-0000 in yii using DetailView?

Thank you, i’ll look into that. The app i’m building isn’t for mobile so this will work just fine. Thank you again.

Did you just talk to a ghost ? ! :mellow::unsure::blink:

no lol he deleted his reply afterwards. But Maskedinput isn’t what i’m looking for. I’m still searching a way to format my attribute to be a phone format.

If you’re sure that the number format will always be the same (specially the length), you could use something like php substr function to reorganize and get the expected format. Maybe it’s not the best way to do it but it is a simple solution and will do the work

i suggested http://demos.krajee.com/masked-input but afterwards i thought that it not solution and i’ve removed comment

Can you do that in GridView?

Please do not delete comments :P

Makes it hard to follow.

You can use strike-out and edit if you feel you need to modify a post you are not happy with.

The alternative is confusing :lol:

Yes, you can customize the column value like this:




'columns' => [

        ...

        [

            'label' => 'Label', //label to be displayed

            'attribute' => 'attribute', //the attribute name

            'value' => 'place your code here', //you can also call a function here 

            'format' => 'raw', //yii2 documentation -> yii\grid\DataColumn  you can check the types

        ],

    ],



here is my code and i got an error: Object of class Closure could not be converted to string


DetailView::widget([

        'model' => $model,

        'attributes' =>


        [

            'id',

            'C1:date',

            'C2:time',

            [

                'label' => 'C3',

                'attribute' => 'C3',

                'value' => function($model){ return $model->C3;},

                'format' => 'raw',


            ],

            'C4',

            'C5',

            'C6',

            'C7',

            'C8',

            'C9',

            'C10',

        ],

    ])

what inside $model->C3? Looks like there not a string, but it must be string

C3 is supposed to be a phone number 0000000000. I want it to display (000) 000-0000 in a GridView.

PS: sorry i’m talking about DetailView not GridView.