dev-master
9999999-dev http://github.com/srusakov/yii2-activeresponseYii2 ajax module with active control from server side
BSD 3-Clause
by rusakov
yii2 ajax
Yii2 ajax module with active control from server side
Yii2 ajax module with active control from server side. Most of existing ajax modules for Yii2 use javascript logic. yii2-ativeresponse is controlled from the server side. All actions you add in PHP controller will be executed with corresponding jQuery function. See Usage for details., (*1)
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
$ php composer.phar require srusakov/yii2-ativeresponse "dev-master"
or add, (*4)
"srusakov/yii2-ativeresponse": "dev-master"
to the require
section of your composer.json
file., (*5)
yii2-ativeresponse
to your layout fileActiveResponse::registerAssets($this);
this will register all necessary javascript files and create global javascript variables., (*6)
<?= Html::a('ActiveResponse Button', null, [ 'href'=>'javascript:void(0);', 'class' => 'btn btn-success', 'onclick'=>"callAR('controller/action');"]) ?>
< form id="theForm" name="theForm" onsubmit="callAR('controller/action', $('#theForm').serializeObject())"> var parameters = $('#theForm').serializeObject(); parameters.your_parameter = 'your value'; callAR('controller/action', parameters);
callAR('controller/action', $('#theForm').serializeObject(), function() { alert('Callback called!'); });
class controllerController extends Controller { public function actionAction() { $ar = new \srusakov\activeresponse\ActiveResponse(); // show standart browser's alert $ar->alert('called from PHP'); // assign html to div $ar->html('div_id', $this->render('view')); // modify attribute $ar->attr('element', 'data-pjax' '0'); // assign value to element $ar->val('element', 'new value'); // modify css $ar->css('element', 'cssattr', 'value'); //redirect $ar->redirect('/new_page.php'); // evaluate javascript $ar->script("alert('wow!')"); // and much, much more... $ar->focus('element'); $ar->addClass('element', 'class'); $ar->removeClass('element', 'class'); $ar->show('element'); $ar->hide('element'); $ar->fadeIn('element'); $ar->fadeOut('element'); return $ar; }
Example with Delete button inside DagaGrid's ActionColumn, (*7)
Pjax::begin(['options' => ['id' => 'pjax-container']]); echo GridView::widget([ ... 'columns' => [ [ 'class' => ActionColumn::className(), 'template' => '{delete}', 'deleteOptions' => ['data-pjax' => 0, 'class' => 'action-delete'], 'urlCreator' => function($action,$model,$key,$index) { return ["/controller/{$action}", 'id'=>$model->id]; }, ],
And PHP Code inside Controller, (*8)
public function actionDelete($id=null) { $ar = new \srusakov\activeresponse\ActiveResponse(); $model = Model::findOne(['id' => $id]); if ($model) { $model->delete(); } $ar->script("$.pjax.reload({container:'#pjax-container'});"); return $ar; }
yii2-activeresponse is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details., (*9)
Yii2 ajax module with active control from server side
BSD 3-Clause
yii2 ajax