Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter + SimplePie: how to clear results?
#1

[eluser]Rubiz'[/eluser]
Hello all!

I'm using SimplePie in an app and I really loved that!

My app has 2 boxes to feed in the same page: 1 for commom rss feed, and other for podcast feeds. Both with multiple and different feeds.

I need to clear results of the first feed... the first feed news are listed in the second feed box, it shouldn't happen... they are mixing as if I have called only one time the method. I have called twice, with different params.

How can I clear results?

Code for news feed:
Code:
<?
    //SimplePie
        $this->simplepie->set_feed_url(array('http://www.stf.jus.br/portal/RSS/noticiaRss.asp?codigo=1','http://www.stj.gov.br/portal_stj/rss/index.wsp','feed://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml','http://www.agu.gov.br/RSS','http://portal2.tcu.gov.br/portal/pls/portal/TCU_CUSTOM.RSS_TCU_NOTICIAS','feed://jus.uol.com.br/revista/feed'));
        $this->simplepie->set_item_limit(3);
        $this->simplepie->enable_cache(false);
        $this->simplepie->enable_order_by_date(true);
        
        $this->simplepie->init();
        $this->simplepie->handle_content_type();
        
        $feeds = $this->simplepie->get_items();
?>

<h3>Not&iacute;cias</h3>
<ul>
&lt;? for( $i=0; $i<3; $i++ ): ?&gt;

    <li><a >get_permalink()?&gt;" target="_self"><strong>&lt;?=$feeds[$i]->get_title()?&gt;</strong> <br />&lt;?=word_limiter($feeds[$i]->get_content(),19)?&gt; [mais]</a></li>
&lt;? endfor; ?&gt;
</ul>
<a class="see-all" href="&lt;?=base_url()?&gt;index.php/noticias" title="ver todas" target="_self">ver todas</a>

Code for podcast feed:
Code:
<h3>PODCAST</h3>

&lt;?
    //SimplePie
        $feeds = '';
        $this->simplepie->set_feed_url(array('http://imagens.globoradio.globo.com/cbn/podcast/comentaristas/lucia-hippolito.xml',
        'http://imagens.globoradio.globo.com/cbn/podcast/comentaristas/arnaldo-jabor.xml',
        'http://imagens.globoradio.globo.com/cbn/podcast/comentaristas/miriam-leitao.xml',
        'http://imagens.globoradio.globo.com/cbn/podcast/colunas/cbn-direitos-do-consumidor.xml',
        'feed://rss.uolnews.uol.com.br/podcast/fernandorodrigues.xml',
        'feed://rss.uolnews.uol.com.br/podcast/bbcbrasil.xml'));
        $this->simplepie->set_item_limit(1);
        $this->simplepie->enable_cache(false);
        $this->simplepie->enable_order_by_date(true);
        
        $this->simplepie->init();
        $this->simplepie->handle_content_type();
        
        $feeds = $this->simplepie->get_items();
?&gt;

<ul>
    &lt;? for ( $i=0; $i < 3; $i++ ): ?&gt;
    &lt;? $item = $feeds[$i]; ?&gt;
      <li><p><strong>&lt;?=$item->get_author()->get_name()?&gt;</strong><br />
    &lt;?=$item->get_content()?&gt;</p>
          <div class="podcast-wrapper">
              <div id="id_temp_&lt;?=$i?&gt;">
              </div>
          </div>
        </li>
        [removed]
            var flashvars = {
              txt_url_feed: "&lt;?=$item->get_permalink()?&gt;",
              txt_itunes: "&lt;?=$item->get_feed()->subscribe_itunes()?&gt;"
            };
            
            swfobject.embedSWF("&lt;?=base_url()?&gt;_SWF/copy.swf", "id_temp_&lt;?=$i?&gt;", "250", "15", "9.0.0","expressInstall.swf", flashvars);
        [removed]
    &lt;? endfor; ?&gt;
</ul>
<a class="see-all" href="&lt;?=base_url()?&gt;index.php/podcast" title="ver todas" target="_self">ver todas</a>
#2

[eluser]Phil Sturgeon[/eluser]
Try putting $this->simplepie->init(); at the start (before you list the URL's). init = initialize.
#3

[eluser]Rubiz'[/eluser]
It didn't work.

I gess init() in this case is for initialize the settings, and not the method...
#4

[eluser]Rubiz'[/eluser]
Nobody else?

I tried to init the library another ways, It's only lasting to finish the job =(((

Anybody can help?
#5

[eluser]Bjørn Børresen[/eluser]
I know this is an old thread but just posting in case anyone else experience the same issues.

The problem is that CI will reuse the loaded object so calling the method several times will bork. $this->load->library('simplepie') won't create a new instance in $this->simplepie;

The way I fixed it was just doing a $this->load->library('simplepie');

And then using simplepie the normal way:

Code:
$simplepie = new SimplePie();

.. working with that object instead of $this->simplepie;

Tried unloading the library with unset($this->simplepie); to no avail so just did it the simple way.




Theme © iAndrew 2016 - Forum software by © MyBB