DanmuWidget.php 672 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 15/12/13
  6. * Time: 上午10:51.
  7. */
  8. namespace plugins\danmu;
  9. use yii\helpers\Url;
  10. class DanmuWidget extends \yii\base\Widget
  11. {
  12. public $entity;
  13. public $entityId;
  14. public $listUrl = null;
  15. public function init()
  16. {
  17. parent::init();
  18. $this->listUrl = $this->listUrl ?: Url::to(['/danmu/index']);
  19. }
  20. public function run()
  21. {
  22. DanmuAsset::register($this->view);
  23. $this->entity = str_replace('\\', '\\\\', $this->entity);
  24. $script = "initDm('{$this->entity}', {$this->entityId}, '{$this->listUrl}');";
  25. $this->view->registerJs($script);
  26. }
  27. }