PHP code example of pavlinter / yii2-buttons
1. Go to this page and download the library: Download pavlinter/yii2-buttons 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/ */
pavlinter / yii2-buttons example snippets
<?= \pavlinter\buttons\AjaxButton::widget([
/*
'options' => [
'class' => 'btn btn-primary',
],
'spinnerOptions' => [
'class' => 'ab-spinner-black', //ab-spinner-red|ab-spinner-green|ab-spinner-blue|ab-spinner-white
],
*/
'id' => 'my-btn',
'label' => 'My Button',
'ajaxOptions' => [
/*
'dataType' => 'json',
'always' => 'function(jqXHR, textStatus){jQuery(".ab-show-" + abId).hide();jQuery(".ab-hide-" + abId).show();}',
'fail' => 'function(){}',
'then' => 'function(){}',
*/
'url' => ['', 'id' => 5], //default current page
'done' => 'function(data){
}',
],
]);
<?= \pavlinter\buttons\AjaxButton::widget([
'ajaxOptions' => [
'data' => [
'id' => 6,
],
'done' => 'function(data){}',
],
]);
$form = ActiveForm::begin(['id' => 'myForm']);
<?= \pavlinter\buttons\AjaxButton::widget([
'ajaxOptions' => [
'type' => 'post',
'dataType' => 'html',
'beforeSend' => 'function(jqXHR, settings){
//defined abId = id widget;
var data = $("#myForm").serializeArray();
data.push({name: "id",value: abId});
settings.data = $.param(data);
}',
'data' => [],
'done' => 'function(data){
}',
],
]);
$form = ActiveForm::begin([
'id' => 'myTestForm',
]);
public function actionIndex($id = null)
{
...
if (($redirect = Yii::$app->request->post('redirect'))) {
return $this->redirect($redirect);
}
...
return $this->render('index');
}