Download the PHP package stesi/yii2-daterange-validator without Composer

On this page you can find all versions of the php package stesi/yii2-daterange-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-daterange-validator

Yii2-daterange-validator

Daterange validator that allows to validate if a model attribute is a valid date range format. Specially usefull if you want to use a DateRangePicker widget and you want to filter by from/until values

Latest Stable Version Total Downloads Latest Unstable Version License

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json file.

Exemple: Filter an attribute model by date range

Imagine we have a model with a 'created_at' attribute, and we want to filter that timestamp in our grid by a date range. In our grid we have implemented a field or widget like kartik DateRangePicker (see http://demos.krajee.com/date-range) that fills the 'created_at' input with a date range format Ex: 12/08/2014 to 17/08/2015

We need to go to the search model and add the rule to the model. Then, we must to add the $fromDate and $untilDate attributes to the model;

use nerburish\daterangevalidator\DateRangeValidator;

public $fromDate;

public $untilDate;

public function rules()
{
    return [
        [['created_at'], DateRangeValidator::className()]
    ];
}

If the created_at value passed to the search model is a valid format range, $fromDate and $untilDate will be assgined with the respective timestamps Then, we could add to the query the next condition:

$query->andFilterWhere(['between', 'created_at', $this->fromDate, $this->untilDate]);   

In case we want to use other attribute names instead defaults, we should pass the attribute names that will be used like this:

use nerburish\daterangevalidator\DateRangeValidator;

public $myInitialDateName;

public $myUntilDateName;

public function rules()
{
    return [
        [['created_at'], DateRangeValidator::className(), 'fromDateAttribute' => 'myInitialDateName', 'untilDateAttribute' => 'myUntilDateName']
    ];
}

By default, it's expected a date format, and this format is taken from the Yii formatter component, but we can define other formats via parameters. Since only date is passed, automatically the from timestamp is set as 00:00:00, and until timestamp is set as 23:59:59. Also, we can change the separator character. Ex: 12-08-2014 / 17-08-2015

public function rules()
{
    return [
        [['created_at'], DateRangeValidator::className(), 'format' => 'php:d-m-Y', 'separator' => ' / ']
    ];
}

However, if we want to directly pass a datetime instead a date format, then we should configure the validator like this:

public function rules()
{
    return [
        [['created_at'], DateRangeValidator::className(), 'type' => 'datetime', 'format' => 'php:d/m/Y H:i:s']
    ];
}

In case we just want validate that the range is a valid range and not assign the from and until timestamp to the attibute model, we can configure the validator of this manner:

public function rules()
{
    return [
        [['created_at'], DateRangeValidator::className(), 'setAttributes' => false]
    ];
}

All versions of yii2-daterange-validator with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package stesi/yii2-daterange-validator contains the following files

Loading the files please wait ....