Skip to content

Instantly share code, notes, and snippets.

@maximishchenko
Created March 29, 2016 12:02
Show Gist options
  • Save maximishchenko/ef95bba5c0e0545c770a to your computer and use it in GitHub Desktop.
Save maximishchenko/ef95bba5c0e0545c770a to your computer and use it in GitHub Desktop.
Yii2 Pjax Auto Reload Action
<?php
// View File
?>
<?php
$script = <<< JS
$(document).ready(function() {
setInterval(function(){ $("#refreshButton").click(); }, 3000);
});
JS;
$this->registerJs($script);
?>
<?php Pjax::begin(); ?>
<?= Html::a("Refresh", ['site/auto-refresh'], ['class' => 'btn btn-lg btn-primary', 'id' => 'refreshButton']) ?>
<h1>Current time: <?= $time ?></h1>
<?php Pjax::end(); ?>
<?php
// Controller Action
?>
<?php
public function actionAutoRefresh()
{
return $this->render('auto-refresh', ['time' => date('H:i:s')]);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment