title: Codeigniter. RSS parser to add data to db
body: <p>I'm creating a script to get posts from an rss feed and place them into my database. I'll do this with 3-5 different feeds and then I'll print them out in date order regardless of the feed they come from. Some of this works fine, like I can get the rss data from the file using simplepie but I can't seem to then add it to an array (trivial part). </p>
  
  <p>The data from get_title() is coming back as a "SimplePie_Item" instead of just a string "Cannot use object of type SimplePie_Item as array". If I try to echo the data it prints the string out just fine. So I think there's something I don't get about data from objects here, like why I can't just copy the string in to the array. I tried casting but this didn't seem to do anything.</p>
  
  <p>--update_database Method code--</p>
  
  <pre><code>function update_database($options=array())
  {    
      //Check required fields.
      if(!$this-&gt;_required(array('feeds','life'),$options))
        return false;
  
      //Add default values
      $options = $this-&gt;_default(array() ,$options);
  
      if(is_array($options['feeds'])) //Multiple blogs
      {       
  </code></pre>
  
  <p>echo 'is an array';</p>
  
  <pre><code>        //Parse each url and add to db.
          foreach($options['feeds'] as $a =&gt; $u)
          {
  </code></pre>
  
  <p>echo 'Print r = <pre>';print_r($u);echo '</pre>';</p>
  
  <pre><code>echo 'feeds loop = '.$a;
  
  echo 'url = '.$u['url'].'&lt;br /&gt;';
  
  $posts = $this-&gt;fetch_feed( array('url'=&gt;$u['url']) );
  
              //Add to db.
              foreach($posts as $f)
              {   
  
    $add['post_title'] =    (string)$f-&gt;get_title();
    $add['link'] =          (string)$f-&gt;get_link();
    $add['p_description'] = (string)$f-&gt;get_description();
    $add['content'] =       (string)$f-&gt;get_content();
    $add['post_date'] =     (string)$f-&gt;get_date();
    $add['guid'] =          (string)$f-&gt;get_id();
    $add['status'] =        'active';
    $add['blog_id'] =       $u['blog_id'];
  
                  $this-&gt;add_post($f);//Add posts to db.
              }
          }
      }
      else //Single blog.
      {
  echo 'feeds - single feed';
  
  $posts = $this-&gt;fetch_feed( array('url'=&gt;$options['url']) );
  
              //Add to db.
              foreach($posts as $k=&gt;$f)
              {                   
    $add['post_title'] =    (string)$f-&gt;get_title();
    $add['link'] =          (string)$f-&gt;get_link();
    $add['p_description'] = (string)$f-&gt;get_description();
    $add['content'] =       (string)$f-&gt;get_content();
    $add['post_date'] =     (string)$f-&gt;get_date();
    $add['guid'] =          (string)$f-&gt;get_id();
    $add['status'] =        'active';
    $add['blog_id'] =       $options['blog_id'];
  
                  $this-&gt;add_post($f);//Add posts to db.
              }
      }
  } 
  </code></pre>
  
  <p>--fetch_feed method--</p>
  
  <pre><code>  function fetch_feed($options=array())
    {
      $this-&gt;simplepie-&gt;set_feed_url($options['url']);
      $this-&gt;simplepie-&gt;set_cache_location(APPPATH.'cache/rss');
      $this-&gt;simplepie-&gt;init();
      $this-&gt;simplepie-&gt;handle_content_type();
      return $this-&gt;simplepie-&gt;get_items();
    }
  </code></pre>
  
  <p>--add_post method--</p>
  
  <pre><code>    function add_post($options)
      {
          //Check required options.
          if(!$this-&gt;_required(array('post_title','link','p_description','content','post_date','guid','status','blog_id'), $options))
            return false;
  
          //Add default values
          $options = $this-&gt;_default(array() ,$options);  
  
          $this-&gt;db-&gt;set('post_title',$options['title']);
          $this-&gt;db-&gt;set('link',$options['link']);
          $this-&gt;db-&gt;set('p_description',$options['description']);
  $this-&gt;db-&gt;set('content',$options['content']);
  $this-&gt;db-&gt;set('post_date',$options['post_date']);
  $this-&gt;db-&gt;set('guid',$options['guid']);
  $this-&gt;db-&gt;set('status',$options['status']);    
          $this-&gt;db-&gt;set('blog_id',$options['blog_id']);
  
          $this-&gt;db-&gt;insert('posts');
          return $this-&gt;db-&gt;affected_rows();
      }
  </code></pre>
  
  <p>--Controller--</p>
  
  <pre><code>  function simple_pie()
    {
      $this-&gt;load-&gt;model('post_model');
      //$this-&gt;options-&gt;feeds = $this-&gt;post_model-&gt;fetch_feed(array('url'=&gt;'http://testigniter.blogspot.com/feeds/posts/default?alt=rss'));
  
      $urls = array('feeds'=&gt;array( array('url'=&gt;'http://testigniter.blogspot.com/feeds/posts/default?alt=rss','blog_id'=&gt;1) ),'life'=&gt;60);
  
      $this-&gt;options-&gt;result = $this-&gt;post_model-&gt;update_database($urls);
  
      if($this-&gt;options-&gt;result)
      {
        echo 'Passed';
      }
      else
      {
        echo 'Failed';
      }
  
      $this-&gt;load-&gt;view('pages/simplepie_test', $this-&gt;options);  
    }
  </code></pre>
  
  <p>No view is really needed here.</p>