surda/datetime-period

Datetime period control for Nette Framework

v1.0.0 2019-10-16 13:27 UTC

This package is auto-updated.

Last update: 2024-11-17 00:39:43 UTC


README

Build Status Licence Latest stable PHPStan

Installation

The recommended way to is via Composer:

composer require surda/datetime-period

After that you have to register extension in config.neon:

extensions:
    monthPeriod: Surda\DateTimePeriod\DI\MonthPeriodExtension

Configuration

Default

monthPeriod:
    templates:
        default: bootstrap4.default.latte
    useAjax: FALSE

Usage

Presenter

use Surda\DateTimePeriod\MonthPeriod\MonthPeriod;
use Surda\DateTimePeriod\MonthPeriod\MonthPeriodControl;
use Surda\DateTimePeriod\MonthPeriod\TMonthPeriod;

class ProductPresenter extends Nette\Application\UI\Presenter
{
    use TMonthPeriod;

    public function actionDefault(): void
    {
        /** @var MonthPeriodControl $mp */
        $mp = $this->getComponent('mp');

        /** @var MonthPeriod $monthPeriod */
        $monthPeriod = $mp->getMonthPeriod();
    }
}

Template

{control mp} or {control mp template} 

Custom options

class ProductPresenter extends Nette\Application\UI\Presenter
{
    /**
     * @return MonthPeriodControl
     */
    protected function createComponentMp(): MonthPeriodControl
    {
        $control = $this->monthPeriodControlFactory->create();

        $control->onChange[] = function (MonthPeriodControl $control, MonthPeriod $monthPeriod): void {
            $this->redirect('this');
        };

        return $control;
    }
}