PHP code example of antonyz89 / yii2-mdbootstrap

1. Go to this page and download the library: Download antonyz89/yii2-mdbootstrap 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/ */

    

antonyz89 / yii2-mdbootstrap example snippets


use antonyz89\mdb\MDBootstrapAsset;
use yii\web\YiiAsset;

class AppAsset extends AssetBundle
{
    public $basePath = '@webroot';
    public $baseUrl = '@web';

    public $css = [];
    public $js = [];
    public $depends = [
        // ...
        MDBootstrapPluginAsset::class, // 1st
        MDBootstrapAsset::class,       // 2nd
    ];
}

return [
    ...
    'components' => [
       ...
       'i18n' => [
            'translations' => [
                'mdb' => [
                    'class' => PhpMessageSource::class,
                    'basePath' => '@antonyz89/mdb/messages',
                ],
            ],
        ], 
    ]
];

<?= Html::a(
    Html::icon('plus'),
    ['example/create'],
    [
        'id' => 'add_example',
        'class' => 'btn btn-success show-modal', // .show-modal is k function who will be called after submit receiving response from server
        ]
    ]
) 

public function actionCreate()
{
    $model = new Example();

    // check if request is made via modal
    $isModal = $this->request->get('modal');

    if ($model->load(Yii::$app->request->post())) {
        // (opcional) ajax validation (disabled if modal ins't null)
        if (Yii::$app->request->isAjax && !$isModal) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }

        if ($model->save()) {

            // if request is made via modal then return json object
            if ($isModal) {
                $this->response->format = Response::FORMAT_JSON;

                return [
                    // returning [[success => true]] closes modal
                    'success' => true,

                    // your data here
                    'model' => $model,
                    'message' => Yii::t('app', 'Created successfully'),
                ];
            }

            Yii::$app->session->setFlash('success', Yii::t('app', 'Created successfully'));
            return $this->redirect(['index']);
        }
    }

    return $this->render('create', [
        'model' => $model,
    ]);
}
bash
php composer.phar