How To Refresh A Widget Every X Seconds?

Hi,

I have developed a very simple widget to show scrolling news from a XML RSS url.

Now I wish to update widget content every X seconds (probabily with ajax). Can you give me an idea to do that?

In this way I can update my widget version adding this feature.

Thanks.

Two google queries that should get you ahead:

  • js settimeout

  • jquery ajax

Hi,

  1. Put the widget to a new file and add a little javascript for update:



#views/something/_feed.php


<div id="feed">

    <div id="feed_widget">

        <?php 

            $this->widget(

                'ext. ya-simple-feed.YaSimpleFeed',

                array(

                'feedUrl'=>'http://rss.cnn.com/rss/cnn_topstories.rss',

                // feedSpeed must be an INT (OPTIONAL, by default is 5)

                'feedSpeed'=>7,

                // feedDirection must be a string as 'left','right,'up' or 'down' (OPTIONAL, by default is 'left')

                'feedDirection'=>'up',

                )

            ); 

        ?>

    </div>

</div>

<?php 

Yii::app()->clientScript->registerCoreScript('jquery');

Yii::app()->clientScript->registerScript('feed-updater', '

    function updater() {

        $("#feed").load("'.$this->createUrl('ajaxfeed').' #feed_widget", function(){

            setTimeout(updater, 2000);

        });

    }

    setTimeout(updater, 2000);

');



  1. add the actionAjaxFeed to the controller:



#controllers/SomethingController.php

class SomethingController {

  ...

  public function actionAjaxFeed() {

    $this->renderPartial("_feed");

  }

  ...

}



  1. put the feed to the view:



#views/something/index.php


....

$this->renderPartial("_feed");

....



Hi Argent,

I was trying to implement your solution but I did not understand how to call the widget with this structure because the widget is already called in _feed.php moreover with static params.

Use this …this may be useful to you…

http://www.yiiframework.com/extension/livegridview/

Hi,

is there a way to add this feature to my widget? So, in this way I can add this feature and share it with all Yii users updating my widget version.

Any idea?