PHPackages                             vadymsemeniuk/yii2-image-require-validator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vadymsemeniuk/yii2-image-require-validator

ActiveYii2-extension

vadymsemeniuk/yii2-image-require-validator
==========================================

Behavior for validating required image

0685PHP

Since Mar 15Pushed 9y ago1 watchersCompare

[ Source](https://github.com/vadimsemenykv/yii2-image-require-validator)[ Packagist](https://packagist.org/packages/vadymsemeniuk/yii2-image-require-validator)[ RSS](/packages/vadymsemeniuk-yii2-image-require-validator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Total Downloads](https://camo.githubusercontent.com/3750f4913aae8530d3e941bbc52ca1433175ef2bfc52bf5bed42818448e5a7c1/68747470733a2f2f706f7365722e707567782e6f72672f766164796d73656d656e69756b2f796969322d696d6167652d726571756972652d76616c696461746f722f642f746f74616c2e706e67)](https://packagist.org/packages/vadymsemeniuk/yii2-image-require-validator)[![Latest Stable Version](https://camo.githubusercontent.com/e46833fc7e347338337b125106f590909e7e173f8f86aa9dceb9eefee58eacda/68747470733a2f2f706f7365722e707567782e6f72672f766164796d73656d656e69756b2f796969322d696d6167652d726571756972652d76616c696461746f722f762f737461626c652e706e67)](https://packagist.org/packages/vadymsemeniuk/yii2-image-require-validator)[![Dependency Status](https://camo.githubusercontent.com/9ce10328c794e0b073fcb124a54b29158d33b9b5df32d456e216bfdc47939472/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f7068702f766164796d73656d656e69756b3a796969322d696d6167652d726571756972652d76616c696461746f722f6465762d6d61737465722f62616467653f7374796c653d666c6174)](https://www.versioneye.com/php/vadymsemeniuk:yii2-image-require-validator)

Yii2 Image require validator
============================

[](#yii2-image-require-validator)

Extension for validating image, throw EntityToFile model

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist vadymsemeniuk/yii2-image-require-validator "*"

```

or add

```
"vadymsemeniuk/yii2-image-require-validator": "*"

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

An example of usage could be:

Your code must look like this

```
use vadymsemenykv\imageRequireValidator\ImageRequireValidator

/**
 * @property EntityToFile $image
 */
class Article extends ActiveRecord {
    public $titleImage;

    public function getImage()
    {
        return $this->hasOne(EntityToFile::className(), ['entity_model_id' => 'id'])
            ->andOnCondition(['t2.entity_model_name' => static::formName(), 't2.attribute' => EntityToFile::TYPE_ARTICLE_TITLE_IMAGE])
            ->from(['t2' => EntityToFile::tableName()])
            ->orderBy('t2.position DESC');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['titleImage'],
                ImageRequireValidator::className(),
                'errorMessage' => 'Title image cannot be blank.',
                'imageRelation' => 'image',
                'skipOnEmpty' => false
            ],
        ];
    }
}
```

If you save in relation many images, and also want to validate min or|and max num of images your code must look like this:

```
use vadymsemenykv\imageRequireValidator\ImageRequireValidator

/**
 * @property EntityToFile $images
 */
class Article extends ActiveRecord {
    public $titleImages;

    public function getImages()
    {
        return $this->hasMany(EntityToFile::className(), ['entity_model_id' => 'id'])
            ->andOnCondition(['t2.entity_model_name' => static::formName(), 't2.attribute' => EntityToFile::TYPE_ARTICLE_TITLE_IMAGE])
            ->from(['t2' => EntityToFile::tableName()])
            ->orderBy('t2.position DESC');
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['titleImages'],
                ImageRequireValidator::className(),
                'errorMessage' => 'Title images cannot be blank.',
                'validateNum' => true,
                'errorNumMinMessage' => 'Title images count should not be less than 3',
                'errorNumMaxMessage' => 'Title images count should not be more than 6',
                'minNumOfImages' => 3,
                'maxNumOfImages' => 6,
                'imageRelation' => 'images',
                'skipOnEmpty' => false
            ],
        ];
    }
}
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

---

Top Contributors

[![vadimsemenykv](https://avatars.githubusercontent.com/u/8122660?v=4)](https://github.com/vadimsemenykv "vadimsemenykv (11 commits)")

### Embed Badge

![Health badge](/badges/vadymsemeniuk-yii2-image-require-validator/health.svg)

```
[![Health](https://phpackages.com/badges/vadymsemeniuk-yii2-image-require-validator/health.svg)](https://phpackages.com/packages/vadymsemeniuk-yii2-image-require-validator)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
