Notify Growls

CONTROLLER

Remember to add a property data-yea="1" in a link pointing to your yii2 controller action (example)

Success Notify (Try it)

    public function actionNotify()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            \letsjump\easyAjax\EasyAjax::notifySuccess('This is a Success Notify!')
        ];
    }

Info Notify (Try it)

    public function actionNotify()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            \letsjump\easyAjax\EasyAjax::notifyInfo('This is an Info Notify!')
        ];
    }

Warning Notify (Try it)

    public function actionNotify()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            \letsjump\easyAjax\EasyAjax::notifyWarning('This is a Warning Notify!')
        ];
    }

Danger Notify (Try it)

A danger notify with a personalized timer setting

    public function actionNotify()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            \letsjump\easyAjax\EasyAjax::notifyDanger('This is a Danger Notify!', null, ['timer' => 15000])
        ];
    }

Other helpers

CONTROLLER

Remember to add a property data-yea="1" in a link pointing to your yii2 controller action (example)

Confirm alert (Try it)

    public function actionConfirm()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        
        return [
            EasyAjax::confirm('This will fire a growl. Ok?', Url::to(['site/notify']))
        ];
    }

Ajax Redirect (Try it)

This will redirect to an ajax action. For example, this will fire another growl using site/notify action

    public function actionAjaxRedirect()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            EasyAjax::redirectAjax(Url::to(['site/notify']))
        ];
    }

Javascript Redirect (Try it)

This will redirect to a landing page by window.location.href

    public function actionJavascriptRedirect()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return [
            EasyAjax::redirectJavascript(Url::to(['site/landing']))
        ];
    }

Content replace (Try it)

Last click time is never clicked

    public function actionContentReplace()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        
        return [
            EasyAjax::contentReplace(['#time' => date('d/m/Y H:i:s')])
        ];
    }

Form Validation (Try it)

    public function actionValidateForm()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        $contactForm                = new ContactForm();
        
        return [
            EasyAjax::formValidation(['#contact-form' => ActiveForm::validate($contactForm)])
        ];
    }

Pjax Reload (Try it)

Last click time is 12/10/2024 21:20:25

    public function actionPjaxReload()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        
        return [
            EasyAjax::reloadPjax(['#test0'])
        ];
    }

Modals

CONTROLLER

Remember to add a property data-yea="1" in a link pointing to your yii2 controller action (example)

Basic modal (Try it)

    public function actionBasicModal()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        
        return [
            EasyAjax::modalBasic('This is the modal content', 'Modal title'),
        ];
    }

Basic modal without footer (Try it)

    public function actionBasicModalNoFooter()
    {
        Yii::$app->response->format = Response::FORMAT_JSON;
        
        return [
            EasyAjax::modalBasic('This is the modal content', 'Modal title', Modal::SIZE_SMALL, false),
        ];
    }

Tabs

Click on each tab to get the current local date

How it works

View


<?= \yii\bootstrap\Tabs::widget([
    'items' => [
        [
            'label'       => 'Rome',
            'linkOptions' => [
                'data-href' => Url::to(['site/tab', 'id' => 'rome',]),
                'data-yea'  => 1
            ],
            'options'     => ['id' => 'rome'],
        ],
        // ... other tabs
    ]
]) ?>
     

Controller


public function actionTab($id)
{
    $date = new \DateTimeImmutable('now');
    
    $content = [
        'rome' => $date->setTimezone(new \DateTimeZone('Europe/Rome'))->format('l jS \of F h:i:s A'),
        'london' => $date->setTimezone(new \DateTimeZone('Europe/London'))->format('l jS \of F h:i:s A'),
        'new-york' => $date->setTimezone(new \DateTimeZone('America/New_York'))->format('l jS \of F h:i:s A'),
        'calcutta' => $date->setTimezone(new \DateTimeZone('Asia/Calcutta'))->format('l jS \of F h:i:s A'),
    ];
    
    if ( ! array_key_exists($id, $content)) {
        throw new BadRequestHttpException('Your request is invalid');
    }
    
    Yii::$app->response->format = Response::FORMAT_JSON;
    
    return [
        EasyAjax::tab($id, '<p>' . $content[$id] . '</p>')
    ];
}