Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I am aware your $data array was not global and therefore only had scope within the index function.</p> <p>As far as conventions go, I only use models for database connections, but I don't think there are any hard and fast rules.</p> <p> <pre><code>class Main extends Controller{ function index() { $this-&gt;load-&gt;library( 'Simplepie' ); $feed_urls = array ( 'http://feeds.feedburner.com/SputnikmusicNews', 'http://feeds2.feedburner.com/nmecom/rss/newsxml', ); foreach ($feed_urls as $feed_url) { $data['feed'][] = $this-&gt;_get_feed($feed_url); } $data['main_content'] = 'main_view'; $this-&gt;load-&gt;view('includes/template', $data); } function _get_feed($url) { $feed = new SimplePie(); $feed-&gt;set_feed_url($url); $feed-&gt;init(); $count = 0; foreach($feed-&gt;get_items() as $item) { $return[$count]['title'] = $item-&gt;get_title(); $return[$count]['permalink'] = $item-&gt;get_permalink(); $count ++; } return $return; } } </code></pre> <p>This will give you:</p> <pre><code>$data['feed'][0] = details from 1st url $data['feed'][1] = details from 2nd url </code></pre> <p>So to access the title from the 1st article in the 1st feed:</p> <pre><code>$data['feed'][0][0]['title'] //or within the view $feed[0][0]['title']; </code></pre> <p>If you wanted to merge the URL's together you would do something like:</p> <p> <pre><code>class Main extends Controller{ function index() { $this-&gt;load-&gt;library( 'Simplepie' ); $feed_urls = array ( 'http://feeds.feedburner.com/SputnikmusicNews', 'http://feeds2.feedburner.com/nmecom/rss/newsxml', ); foreach ($feed_urls as $feed_url) { $feed_info[] = $this-&gt;_get_feed($feed_url); $data['feed'][] = $this-&gt;_get_feed($feed_url); } foreach ($feed_info as $feed) { foreach($feed as $feed_item) { $data['feed'][] = array( 'title' =&gt; $feed_item-&gt;get_title(), 'permalink' =&gt; $feed_item-&gt;get_permalink() ); } } $data['main_content'] = 'main_view'; $this-&gt;load-&gt;view('includes/template', $data); } function _get_feed($url) { $feed = new SimplePie(); $feed-&gt;set_feed_url($url); $feed-&gt;init(); return $feed; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload