PHP code example of antkaz / yii2-ajax

1. Go to this page and download the library: Download antkaz/yii2-ajax library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

antkaz / yii2-ajax example snippets


    <?= \antkaz\ajax\Modal::widget([
        'id' => 'modal',
        'clientEvents' => [
            'submit.success.bs.modal' => 'function(event, body) {$(this).modal("hide")}'
        ]
    ]); 

    <?= \yii\bootstrap\Html::a('Create', ['create'], [
        'class' => 'btn btn-success',
        'data-toggle' => 'ajax-modal', // outputs the result to the modal window
        'data-target' => '#modal', // ID modal
        'data-title' => 'Create item' // custom modal title
    ]); 

     $form = \yii\bootstrap\ActiveForm::begin([
        'options' => [
            'data-ajax' => 1
        ],
    ]); 

    public function actionCreate()
    {
        $model = new Model();
    
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['index']); // optional
        }
    
        return $this->renderView('create', [
            'model' => $model,
        ]);
    
    }
    
    protected function renderView($view, $params = [])
    {
        if (Yii::$app->request->isAjax) {
            return $this->renderAjax($view, $params);
        }
        return $this->render($view, $params);
    }