Created
March 29, 2016 12:02
-
-
Save maximishchenko/ef95bba5c0e0545c770a to your computer and use it in GitHub Desktop.
Yii2 Pjax Auto Reload Action
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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