Welcome Guest, Not a member yet? Register   Sign In
creating a library
#1

[eluser]karloff[/eluser]
I'm trying to create a library to load my feeds so i only have one lin in my controller (i'm using a template to to do most of the hard work). Before i had loaded a library which pulled the feeds, but i had to send the data to the view in every controller.

Is it possible to load the data and pass it to the cntroller so i would only have one line of code

here is the library thang i got....
Code:
<?

class Feeds {



function get_feeds()
{

$CI =& get_instance();
$CI->load->library('simplepie');
$CI->simplepie->set_feed_url('http://feeds.delicious.com/rss/username');
$CI->simplepie->init();

$CI->load->library('lastfm');

$config = array(
'user' => 'username',
'num' => 5,
'rss_cache_path' => APPPATH.'cache/lastfm-rss-cache',
'cache_time' => 300 // 5 minutes
);

$CI->lastfm->init($config);

$CI->lastfm->get_latest();


$CI->load->library('flickr');

$config = array(
'type' => 'user',
'user' => 'username',
'num_items' => 8,
'rss_cache_path' => APPPATH.'cache/flickr-rss-cache',
'cache_time' => 3600,
'img_cache_path' => APPPATH.'cache/flickr-image-cache',
'img_cache_url' => $CI->config->item('base_url').'application/cache/flickr-image-cache',
'use_cache' => false,
'image_size' => 'square'

);

$CI->flickr->init($config);

$CI->flickr->get_photos();
return $feeds;
}


}
?>

can anyone enlighten me on how I can then pass this through the controller to the view? Or a better way of doing it?
#2

[eluser]pistolPete[/eluser]
Quote:can anyone enlighten me on how I can then pass this through the controller to the view?

Put the class into ./system/applicatio/libraries/feeds.php.
Load it in your controller:
Code:
$this->load->library('feeds');
$data['feeds'] = $this->feeds->get_feeds();
$this->load->view('view_file', $data);

But the library should actually return the data instead of the yet empty variable $feeds.
#3

[eluser]karloff[/eluser]
i had that before, however the $data was coming back empty so I thought i had takedn the wrong approach...

I have this in my feeds

$data['delicious'] = $CI->simplepie->get_items(0,5);


etc.....

and the data of delicious is empty every time... I'm i missing something?
#4

[eluser]pistolPete[/eluser]
In the code you posted above you return an empty variable $feeds.
You need return the data your library just gathered, e.g.:
Code:
$data = array();
...
$data['lastfm'] = $CI->lastfm->get_latest();

...
$data['flickr'] = $CI->flickr->get_photos();
...
return $data;
#5

[eluser]Fenix[/eluser]
No Digg stream? Wink

http://apidoc.digg.com/
#6

[eluser]karloff[/eluser]
spot on Pete... simple. thanks

@Fenix... not much of a digger Wink




Theme © iAndrew 2016 - Forum software by © MyBB