H
H
hollanditkzn2017-04-21 11:24:48
Yii
hollanditkzn, 2017-04-21 11:24:48

Is it possible to connect prefix to id?

Is it possible to add a prefix to the id in the database? Now I have implemented only like this in the gridview

[
                'attribute' => 'id_zakaz',
                'headerOptions' => ['width' => '20'],
                'value' => function($model) {
                    if ($model->id_sotrud == 2) {
                       return 'M-'.$model->id_zakaz;
                    } 
                    return $model->id_zakaz;
                    print_r($model->id_zakaz);
                }
            ],

Then if id_sotrud is equal to a certain id, then a certain letter is assigned.
Or is it better to do it in the model?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-04-21
@hollanditkzn

print_r($model->id_zakaz);- this will never be executed at all.
This:

if ($model->id_sotrud == 2) {
                       return 'M-'.$model->id_zakaz;
                    } 
                    return $model->id_zakaz;

can be shortened:
But it is better to take out into the model:
public function getMyCrazyHren(){
return ($this->id_sotrud == 2)?'M-'.$this->id_zakaz:$this->id_zakaz;  
}

and in grid:
[
                'attribute' => 'id_zakaz',
                'headerOptions' => ['width' => '20'],
                'value' => 'myCrazyHren',
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question