gridview에서 모델의 데이터를 호출하려고했습니다. 작곡가를 통해 고급 그리드 뷰를 설치했고 \ yiister \ grid \ widgets \ ProgressColumn을 사용하고 있습니다. 하지만 prolem의 ProgressColumn 위젯yii2 gridview Closure 클래스의 객체를 int로 변환 할 수 없습니다.
int 값으로'value'=>function($model){
$model->paxtashart;
},
를 참가하는 것은, 그것은 나에게 오류를 제공 : 클래스 폐쇄의 개체
을 int로 변환 할 수 없습니다 나는에 변환 할 수있는 possiblity가가 int 또는 다른 대안? 여기
내가 당신에게 내 전체 코드를 제시하자
$model->paxtashart
하지만 모든 속성에 대해 나에게 한 값을 제공 jsut, 그것은
도움이되지 않고있다 :이 방법을 시도[
'class' => \yiister\grid\widgets\ProgressColumn::className(),
'attribute' => 'paxta_given',
'size' => \yiister\grid\widgets\ProgressColumn::SIZE_LARGE,
'isAnimated' => true,
'value'=>function($model){
$model->paxtashart;
},
// 'maxValue'=> $fermercha->paxtashart,
// 'minValue'=> $fermercha->paxta_given,
'progressBarClass' => function ($model, $column) {
return $model->{$column->attribute} > 60
? \yiister\grid\widgets\ProgressColumn::STYLE_SUCCESS
: \yiister\grid\widgets\ProgressColumn::STYLE_WARNING;
},
],
내 모델은 다음과 같습니다.
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "fermer".
*
* @property integer $id
* @property string $FIO
* @property integer $tuman_id
* @property string $Massiv
* @property integer $ferhojalik
* @property integer $maydoni
* @property integer $paxtamay
* @property integer $paxtashart
* @property integer $gallamay
* @property integer $gallashart
* @property integer $bog
* @property integer $uzum
* @property integer $poliz
* @property integer $sabzavot
* @property integer $chorva
*/
class Fermer extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'fermer';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['tuman_id', 'ferhojalik', 'maydoni', 'paxtamay', 'paxtashart', 'gallamay', 'gallashart', 'paxta_given', 'poliz', 'sabzavot', 'chorva','paxta_done'], 'integer'],
[['FIO', 'Massiv'], 'string', 'max' => 255],
[['image'], 'file', 'extensions' => ['png','jpg','jpeg']],
];
}
public function upload()
{
if ($this->validate() and $this->image->baseName) {
$this->image->saveAs(Yii::$app->basePath.'/web/uploads/' . $this->image->baseName . '.' . $this->image->extension);
return true;
} else {
return false;
}
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'FIO' => 'ФИО',
'tuman_id' => 'Туман номи',
'Massiv' => 'Массив номи',
'ferhojalik' => 'Фермер хўжалиги номи',
'maydoni' => 'Майдони',
'paxtamay' => 'Пахта майдони',
'paxtashart' => 'Пахта майдони шартнома режаси (тонна)',
'gallamay' => 'Ғалла майдони',
'gallashart' => 'Ғалла майдони шартнома режаси (тонна)',
'paxta_given' => 'Пахта шартнома бўйича топширилган тонна',
'image' => 'Расм',
'poliz' => 'Полизчилик',
'sabzavot' => 'Сабзавотчилик',
'chorva' => 'Чорвачилик',
];
}
// return $this->hasone(Extraagri::className(), ['id' => 'po_item_no']);
public function getDone()
{
return $this->hasone(done::classname(),['id'=>'paxta_done']);
}
/* public function getPoitem()
{
return $this->hasMany(Poitem::className(), ['id' => 'po_item_no']);
}*/
/* public function getExtraagri()
{
return $this->hasMany(Extraagri::className(), ['id' => 'id']);
}
*/
}
'return $ model-> paxtashart'와 같은 값을 추가하기 전에 어떻게해야합니까? –
반환 값을 추가했지만 여전히 오류가 발생합니다. 클래스 Closure의 객체를 int로 변환 할 수 없습니다 –
변수에 클로저를 미리 지정해보십시오. '$ paxtashart = function ($ model) { 과 같이 return $ model-> paxtashart; }'. 그런 다음'value => (int) $ paxtashart()'처럼 호출하십시오. BTW,'$ model'은 무엇입니까? 여기에 더 많은 코드를 추가 할 수 있습니까? –