Помогите!! zxbodya/yii2-gallery-manager Call to a member function getBehavior() on null

Общие вопросы по использованию второй версии фреймворка. Если не знаете как что-то сделать и это про Yii 2, вам сюда.
Ответить
alex290
Сообщения: 10
Зарегистрирован: 2017.10.09, 15:24

Помогите!! zxbodya/yii2-gallery-manager Call to a member function getBehavior() on null

Сообщение alex290 »

Помогите пожалуйста с zxbodya/yii2-gallery-manager

Сделал по инструкции

создал модель

Код: Выделить всё

<?php

namespace app\models;

use Yii;
use zxbodya\yii2\galleryManager\GalleryBehavior;

/**
 * This is the model class for table "gallery_image".
 *
 * @property integer $id
 * @property string $type
 * @property string $ownerId
 * @property integer $rank
 * @property string $name
 * @property string $description
 */
class Gallery extends \yii\db\ActiveRecord {

    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'gallery_image';
    }

    public function behaviors() {
        return [
            'galleryBehavior' => [
                'class' => GalleryBehavior::className(),
                'type' => 'galery',
                'extension' => 'jpg',
                'directory' => '/web/upload/gallery',
                'url' => '/web/upload/gallery',
                'versions' => [
                    'small' => function ($img) {
                        /** @var \Imagine\Image\ImageInterface $img */
                        return $img
                            ->copy()
                            ->thumbnail(new \Imagine\Image\Box(200, 200));
                    },
                    'medium' => function ($img) {
                        /** @var Imagine\Image\ImageInterface $img */
                        $dstSize = $img->getSize();
                        $maxWidth = 800;
                        if ($dstSize->getWidth() > $maxWidth) {
                            $dstSize = $dstSize->widen($maxWidth);
                        }
                        return $img
                            ->copy()
                            ->resize($dstSize);
                    },
                ]
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['ownerId'], 'required'],
            [['rank'], 'integer'],
            [['description'], 'string'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'type' => 'Type',
            'ownerId' => 'Owner ID',
            'rank' => 'Rank',
            'name' => 'Name',
            'description' => 'Description',
        ];
    }

}

Контроллер

Код: Выделить всё

<?php

namespace app\modules\admin\controllers;

use app\models\Gallery;
use zxbodya\yii2\galleryManager\GalleryManagerAction;

class GalleryController extends \yii\web\Controller
{
    public function actions()
    {
        return [
            'galleryApi' => [
                'class' => GalleryManagerAction::className(),
                // mappings between type names and model classes (should be the same as in behaviour)
                'types' => [
                    'galery' => Gallery::className()
                ]
            ],
        ];
    }

    public function actionIndex()
    {
        $dataProvider = Gallery::find()->all();
        return $this->render('index', ['model' => $dataProvider[0]]);
    }


}
Ну и наконец вьюшку

Код: Выделить всё

<?php

use zxbodya\yii2\galleryManager\GalleryManager;
?>


<div class="row">
    <div class="col-xs-12 text-center">
        <div class="panel panel-default">
            <div class="panel-heading">Галерея "Фото"</div>
            <div class="panel-body">
                <?php
                if ($model->isNewRecord) {
                    echo 'Can not upload images for new record';
                } else {
                    echo GalleryManager::widget(
                            [
                                'model' => $model,
                                'behaviorName' => 'galleryBehavior',
                                'apiRoute' => 'admin/gallery/galleryApi'
                            ]
                    );
                }
                ?>
            </div>
        </div>
    </div>
</div>


Выдает ошибку Call to a member function getBehavior() on null

Изображение

Что я сделал ни так

ПОМОГИТЕ!!
Ответить