Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.
Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin. Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

yii2 Object of class Closure could not be converted to int

+1 ovoz
110 marta ko‘rilgan
so‘radi 29 oktabr, 17 alfraganus (812 bal)

Assalomu Aleykum,

men yii2 gridview ichida progressbar qilmoqchi edim, oddiy gridview buni imkoni bolmagani uchun advanced grid view widgetni composer orqali ornattim, va 

[

'attibute'=>'paxta'

value=>'function($model){

return $model->kg;

}',

]

deb kirgissam quyidagi xatolikni beryapdi:

Object of class Closure could not be converted to int

oddiy grid view bu xatolik chiqmasdi ammo  shu class uchdiua beryapdi

 [
    'class' => \yiister\grid\widgets\ProgressColumn::className(),
    'attribute' => 'paxta_given',
    'size' => \yiister\grid\widgets\ProgressColumn::SIZE_LARGE,
    'isAnimated' => true,
     'value'=> function($model)

{
$model->kg;

},
 
 
    'progressBarClass' => function ($model, $column) {
        return $model->{$column->attribute} > 60
            ? \yiister\grid\widgets\ProgressColumn::STYLE_SUCCESS
            : \yiister\grid\widgets\ProgressColumn::STYLE_WARNING;
    },
],

oddiy yo'l bn ham berib kordim, function yozmasdan, $model->kg, lekin unda men kugan natifa bomayapdi, har bir databazadan kelgan malumotga faqat 1 xil natija beryapdi, men function bilan berishim kerek, lekin unda bu uni string deb oylabyapdi va int ga aylantirish kerke deb xatolik beryapdi. biror yo'li bormi?

1 ta javob

0 ovoz
javob berdi 29 oktabr, 17 Farhodjon (1,192 bal)
modeldi print bilan chiqarib koring. siz qayerdadur objectni int ornida ishlatib ketgansiz. xatilikda kodni qatori ham korsatiladi oshani korsez xato aynan qayerda ekanligini korasiz
izoh qoldirdi 29 oktabr, 17 alfraganus (812 bal)
quyidagi xatolik chiqyapdi:

PHP Notice – yii\base\ErrorException

Object of class Closure could not be converted to int
1. in C:\xampp\htdocs\tomorqa_local\vendor\yiister\yii2-advanced-grid\src\widgets\ProgressColumn.php at line 126
117118119120121122123124125126127128129130131132133134135        }
    }
 
    /**
     * @inheritdoc
     */
        // $data = ($model->{$this->value});
    protected function renderDataCellContent($model, $key, $index)
    {
     $percents = ($model->{$this->attribute}) * 100 /  $this->value;
        $progressBarClass = $this->_progressBarClass . ' ' . (is_callable($this->progressBarClass)
            ? call_user_func($this->progressBarClass, $model, $this)
            : $this->progressBarClass);
        return Html::tag(
            'div',
            Html::tag(
                'div',
                $this->showText ? Html::tag('span', $this->percent ? $percents . '%' : $model->{$this->attribute}) : '',
                [


bu esa 126 qatorgadi kod:

     $percents = ($model->{$this->attribute}) * 100 /  $this->value;

Assalomu alaykum, yordam.uz saytimizga xush kelibsiz.

Bu saytda o`zingizni qiziqtirgan savollarga javob olishingiz va o`z sohangiz bo`yicha savollarga javob berishingiz mumkin.

Bizning Oilamizga a'zo bo`lganingiz uchun chuqur Minnatdorchilik bildiramiz !!!

Telegram kanal YordamUzRss

...