CodeIgniter Forums
Resetting a Library for reuse - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Resetting a Library for reuse (/showthread.php?tid=7837)



Resetting a Library for reuse - El Forum - 04-24-2008

[eluser]kevinprince[/eluser]
I'm trying to use the RSSparser library with 3 rss feeds, each needs to be loaded up and put into a html page.

The outputed values seems to be that which ever feed is called first.


Any idea on if i can reset the library after each use?

Code:
$id = $this->uri->segment(3, 0);
        $archive = $this->Archive->get_archive($id);
        $template = $this->Template->get_template($archive['template']);
        $templatename = $template['filename'];
        
        $feed = "./assets/" . $id . "/master.xml";
        $feedb  = "./assets/" . $id . "/feedb.xml";
        $feedc  = "./assets/" . $id . "/feedc.xml";
        
        $date = date('d-m-y');    
        
        $this->load->library('RSSParser', array('url' => $feed, 'life' => 0));
        
        $data['master'] = $this->rssparser->getFeed(50);
        
        $this->load->library('RSSParser', array('url' => $feedb, 'life' => 0));
        
        $data['feedb'] = $this->rssparser->getFeed(50);
        
        $this->load->library('RSSParser', array('url' => $feedc, 'life' => 0));
        
        $data['feedc'] = $this->rssparser->getFeed(50);
                
        $this->load->view('templates/' . $templatename, $data);



Resetting a Library for reuse - El Forum - 04-24-2008

[eluser]nmweb[/eluser]
The more elegant way to do this is just use instances of the object. In CI this would look like
<php>
$id = $this->uri->segment(3, 0);
$archive = $this->Archive->get_archive($id);
$template = $this->Template->get_template($archive['template']);
$templatename = $template['filename'];

$feed = "./assets/" . $id . "/master.xml";
$feedb = "./assets/" . $id . "/feedb.xml";
$feedc = "./assets/" . $id . "/feedc.xml";

$date = date('d-m-y');

$this->load->library('RSSParser', array('url' => $feed, 'life' => 0));

$data['master'] = $this->rssparser->getFeed(50);

$data['feedb']=new RSSParser(array('url' => $feedb, 'life' => 0));

$data['feedb'] = $data['feedb']->getFeed(50);

$data['feedc']=new RSSParser(array('url' => $feedc, 'life' => 0));

$data['feedc'] = $data['feedc']->getFeed(50);

$this->load->view('templates/' . $templatename, $data);
</php>
Something like this


Resetting a Library for reuse - El Forum - 04-25-2008

[eluser]kevinprince[/eluser]
Going to sound like th FNG but I just tried what you suggested and some variations and I get

Code:
Message: Undefined property: RSSParser::$RSSParser

I assume this is because it isnt working as an instance.

Suggestions welcome.


Resetting a Library for reuse - El Forum - 04-25-2008

[eluser]xwero[/eluser]
Instead of loading the library several times, which doesn't work because it will be loaded only once, you should add a initialize method to your library like the File uploading library