PHP code example of marekpetras / yii2-ajax-box-widget
1. Go to this page and download the library: Download marekpetras/yii2-ajax-box-widget 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/ */
marekpetras / yii2-ajax-box-widget example snippets
use marekpetras\yii2ajaxboxwidget\Box;
echo marekpetras\yii2ajaxboxwidget\Box::widget($options);
$box = marekpetras\yii2ajaxboxwidget\Box::begin($options);
// write body content here
echo 'Body';
// add some tools
$box->tools();
echo 'Tools';
// add some footer
$box->footer();
echo 'Footer';
$box->end();
$options = [
'title' => 'My Box',
'subtitle' => 'About us',
'type' => 'info',
'invisible' => false,
'bodyLoad' => ['test/my', 'var' => 'value'],
'toolsTemplate' => '{tools} {reload} {collapse} {remove} {myButton}',
'toolsButtons' => [
'myButton' => function() {
return \yii\helpers\Html::button('my button');
},
],
'toolsButtonOptions' => [
'class' => 'myButtons',
],
'autoload' => true,
'hidden' => false,
'data' => [
'postvar1' => 123,
'postvar2' => 234,
],
'clientOptions' => [
'autoload' => true, // modify this with the general option not here though
'onerror' => new \yii\web\JsExpression('function(response, box, xhr) {console.log(response,box,xhr)}'), // loads the error message in the box by default
'onload' => new \yii\web\JsExpression('function(box, status) { console.log(box,status); }'), // nothing by default
],
'classes' => ['box', 'box-flat', 'box-init'],
'view' => '@path/to/your/view',
];
class BaseController extends \yii\base\Controller
{
/**
* @inheritdoc
*/
public function render($view, $params = [])
{
if ( Yii::$app->request->getIsAjax() ) {
Yii::trace('Rendering AJAX');
return parent::renderAjax($view, $params);
}
else {
return parent::render($view, $params);
}
}
}
use marekpetras\yii2ajaxboxwidget\Box;
use yii\helpers\Html;