Class kartik\daterange\DateRangeBehavior

Inheritancekartik\daterange\DateRangeBehavior » yii\base\Behavior » yii\base\BaseObject
Implementsyii\base\Configurable

DateRangeBehavior automatically fills the specified attributes with the parsed date range values to work seamlessly with the kartik\daterange\DateRangePicker widget.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$attribute string The attribute that containing date range value. kartik\daterange\DateRangeBehavior
$dateAttribute string The attribute that will receive date value formatted by $dateFormat. kartik\daterange\DateRangeBehavior
$dateEndAttribute string The attribute that will receive range end value formatted by $dateEndFormat. kartik\daterange\DateRangeBehavior
$dateEndFormat string|null|false The PHP date format string. kartik\daterange\DateRangeBehavior
$dateFormat string|null|false The PHP date format string. kartik\daterange\DateRangeBehavior
$dateStartAttribute string The attribute that will receive range start value formatted by $dateStartFormat. kartik\daterange\DateRangeBehavior
$dateStartFormat string|null|false The PHP date format string. kartik\daterange\DateRangeBehavior
$owner yii\base\Model The owner model of this behavior. kartik\daterange\DateRangeBehavior
$separator string The date range separator. kartik\daterange\DateRangeBehavior
$singleDate boolean Whether the attribute is a single date. kartik\daterange\DateRangeBehavior

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
afterValidate() Handles owner 'afterValidate' event. kartik\daterange\DateRangeBehavior
attach() Attaches the behavior object to the component. yii\base\Behavior
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
detach() Detaches the behavior object from the component. yii\base\Behavior
events() Declares event handlers for the $owner's events. kartik\daterange\DateRangeBehavior
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. kartik\daterange\DateRangeBehavior

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
dateToTime() Parses the given date into a Unix timestamp. kartik\daterange\DateRangeBehavior
setOwnerAttribute() Evaluates the attribute value and assigns it to the given attribute. kartik\daterange\DateRangeBehavior

Property Details

$attribute public property

The attribute that containing date range value.

public string $attribute 'date_range'
$dateAttribute public property

The attribute that will receive date value formatted by $dateFormat. Required when $singleDate is set to true.

public string $dateAttribute null
$dateEndAttribute public property

The attribute that will receive range end value formatted by $dateEndFormat. Required when $singleDate is set to false.

public string $dateEndAttribute null
$dateEndFormat public property

The PHP date format string. It will be used to format the range end value.

  • If set to null, this will auto convert the range end value into a Unix timestamp.
  • If set to false, there is no formatting action on the range end value.

See also [[$dateEndAttribute]].

$dateFormat public property

The PHP date format string. It will be used to format the date value.

  • If set to null, this will auto convert the date value into a Unix timestamp.
  • If set to false, there is no formatting action on the date value.

See also [[$dateAttribute]].

public string|null|false $dateFormat null
$dateStartAttribute public property

The attribute that will receive range start value formatted by $dateStartFormat. Required when $singleDate is set to false.

$dateStartFormat public property

The PHP date format string. It will be used to format the range start value.

  • If set to null, this will auto convert the range start value into a Unix timestamp.
  • If set to false, there is no formatting action on the range start value.

See also [[$dateStartAttribute]].

$owner public property

The owner model of this behavior.

public yii\base\Model $owner null
$separator public property

The date range separator.

public string $separator null
$singleDate public property

Whether the attribute is a single date.

public boolean $singleDate false

Method Details

afterValidate() public method

Handles owner 'afterValidate' event.

public void afterValidate ( $event )
$event yii\base\Event

Event instance.

throws yii\base\InvalidValueException
dateToTime() protected static method

Parses the given date into a Unix timestamp.

protected static integer|false dateToTime ( $date )
$date string

A date string

return integer|false

A Unix timestamp. False on failure.

events() public method

Declares event handlers for the $owner's events.

Child classes may override this method to declare what PHP callbacks should be attached to the events of the $owner component.

The callbacks will be attached to the $owner's events when the behavior is attached to the owner; and they will be detached from the events when the behavior is detached from the component.

The callbacks can be any of the following:

  • method in this behavior: 'handleClick', equivalent to [$this, 'handleClick']
  • object method: [$object, 'handleClick']
  • static method: ['Page', 'handleClick']
  • anonymous function: function ($event) { ... }

The following is an example:

[
    Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
    Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
]
public array events ( )
return array

Events (array keys) and the corresponding event handler methods (array values).

init() public method

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

public void init ( )
throws yii\base\InvalidConfigException
setOwnerAttribute() protected method

Evaluates the attribute value and assigns it to the given attribute.

protected void setOwnerAttribute ( $attribute, $dateFormat, $date )
$attribute string

The owner attribute name

$dateFormat string

The PHP date format string

$date string

The date string