@Maila

Yii2 advanced model search -как исправить ошибку?

В админ панели admin.site.com/blog/index появляется такая ошибка: f4cc0037621d460cb4553d17eace0ef1.jpg Код Blog.php
(D:\sites\site\yii2\common\models)
<?php

namespace common\models;

use Yii;
use common\models\Blog;

/**
 * This is the model class for table "blog".
 *
 * @property integer $id
 * @property string $title
 * @property string $text
 * @property string $url
 * @property integer $status_id
 * @property integer $sort
 */
class Blog extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'blog';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title', 'url'], 'required'],
            [['text'], 'string'],
            [['status_id', 'sort'], 'integer'],
            [['sort'], 'integer','max'=>99, 'min'=>1],
            [['title', 'url'], 'string', 'max' => 150],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => 'Заголовок',
            'text' => 'Текст',
            'url' => 'ЧПУ',
            'status_id' => 'Статус',
            'sort' => 'Сортировка',
        ];
    }

    public static function getStatusList() {
        return ['off','on'];
}
    public function getStatusName(){
       $list = self::getStatusList();
       return $list($this->status_id);
    }
}
Файл index.php (D:\sites\site\yii2\backend\views\blog)
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
/* @var $this yii\web\View */
/* @var $searchModel common\models\BlogSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Blogs';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="blog-index">

     
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Blog', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
<?php Pjax::begin(); ?>  


 <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'title',
            'url:url',
/* ['attribute'=>'status_id','filter'=>['off','on'],'value'=>function ($model){
     $status = 'off';
    if($model->status_id ==1) {
        $status = 'on';
         }
    return $status; 
 }], */

['attribute'=>'status_id','filter'=>\common\models\Blog::getStatusList(),'value'=>function ($model){
     return $model->statusName;
 }],
     'sort',
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

<?php Pjax::end(); ?></div>
  • Вопрос задан
  • 122 просмотра
Решения вопроса 1
@Snewer
return $list($this->status_id); to return $list[$this->status_id];
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы