![]() |
RSS aggregator - 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: RSS aggregator (/showthread.php?tid=2805) |
RSS aggregator - El Forum - 08-25-2007 [eluser]Kurai[/eluser] Hi everyone. I'm really starting with CI, I like it al lot, but, not being a much of a coder, something is still difficult to figure out for me. I'm trying to do an RSS aggregator, which displays several sources in several ways (I.E: the last post from a blog, flickr images, the most n recent posts for another blog and so on). Right now I'm proceeding like this: I've made an aggregator view which act as a container, and several other views for various bits of codes (header, footer, and the various RSS boxes) to easily edit them. Then I've installed Simplepie as a class and tried fetching a single RSS source, following literally the tutorial at http://www.nextbigleap.com/blog/development/simplepie-rss-class-and-codeigniter/. This worked pretty fine, but I'm stuck now. I know I should create a function which takes an url as an argument and then returns the array with the rss feed, but I can't figure out where to create it (a new library maybe?) and how to call it correctly from the view in which I want to display my feed. I know thisi is probably quite stupid as a question, but I still have difficulties in understanding the differences between classes, models and libraries. Can anyone lend me a hand? Thank you! RSS aggregator - El Forum - 08-25-2007 [eluser]NemetraL[/eluser] Following the MVC principles, it's not the view that will call your library, it's the controller. The controller calls the library, puts the data in a variable and calls the view with this variable as an argument. For your last question, controllers/models/libraries are all classes in that they're all coded in OOP way. RSS aggregator - El Forum - 08-25-2007 [eluser]codelearn[/eluser] Kurai - I actually had to whip up something like this really quickly yesterday: Using simplepie... Code: $count = 1; $feeds is an array of all the URL's you want to pass. Am I answering the correct question? RSS aggregator - El Forum - 08-26-2007 [eluser]Kurai[/eluser] Ok, I'm not sure, then, if I followed the correct path. Basically what I did was a new library with the class to fetch an RSS, getting only the parameters I really need. This way I could take advantage of simplepie built-in commands: Code: class Rss { Then I called that function from my view, passing the url and constructing the HTML: Code: <div id="blog1"> I did this mainly because I didn't want to fetch too much data from the RSS, but seeing your advices I'm not so convinced this is the best way to go. What do you think? If I build an array with all the RSS feed, is there a simple way to retrieve the single elements (say, the post title or the permalink)? Thank you! RSS aggregator - El Forum - 08-26-2007 [eluser]NemetraL[/eluser] In your controller, just do: Code: $this->load->library('rss'); Then in the view (the template_name file): Code: <div id="blog1"> Last thing: aren't you retrieving only the last RSS item in your blogblock() function? RSS aggregator - El Forum - 08-26-2007 [eluser]Kurai[/eluser] That's right. I set it up this way, for now, but I will accept as a parameter the number of entry to display. This was just for testing purposes. Another thing: using the way you suggested, how can I set up multiple RSS blocks (each with its URL)? Rightt now the controller doesn't directly load the blog1 view. It loads a container view which composes a header, a footer and several RSS blocks. The problem is that I don't know how to pass each data to its own block, since it seems that if I call two or more views in the controller only the last is applied... RSS aggregator - El Forum - 08-26-2007 [eluser]NemetraL[/eluser] Plenty of posts regarding this issue.. even an entry in the wiki. It's commonly called 'displaying multiple views'. Basically, with CI's standard features, you put the partial view in a variable and then you transmit this variable to the final view using: Code: $data['blog1'] = $this->view->load('blog1_partial_view', $rss, true); Other ways of doing it exist: look at Coolfactor's View library for example. RSS aggregator - El Forum - 08-26-2007 [eluser]Kurai[/eluser] Thank you very much. I haven't thought this way to build multiple views, and I was stuck, because with the container method I just can't pass different objects to different views. I go check the wiki and the Coolfactor library. RSS aggregator - El Forum - 08-26-2007 [eluser]NemetraL[/eluser] You're welcome. Happy coding ;-) RSS aggregator - El Forum - 08-26-2007 [eluser]Kurai[/eluser] Seems I'm still not so good... I tried the code you proposed, bu it seems I can't get it to work. It sendss me an error: Quote:A PHP Error was encountered I used this code for the controller: Code: $this->load->library("rss"); Then for the view of a single blog source: Code: <div id="blog1"> (and I used the exact same code for blog2 view, changing $source1 in $source2) Finally, the composite view has this code (I omit html and head, it's just the boy content) Code: <div class="content"> Where I am wrong? It seems that the approach of CodeIgniter in this kind of problem is not so obvious... am I forgetting something? Thank you! |