dgoosens Posted December 2, 2009 Share Posted December 2, 2009 hi freaks, This is my situation... I am trying to dive into Zend Framework and to do so I got Zend Framework in Action by Rob ALLEN. I am now playing around with Zend_Services, namely Zend_Service_Flickr. Everything works great, getting the images etc. But, as this is rather heavy, I'd need to cache my Flickr result. This is my Flickr class: class Flickr { protected $apikey; public function __construct() { $this->apikey = Zend_Registry::get('config')->flickr_api_key; } public function search($keywords, $amount = 6) { if(empty ($this->apikey)) { return null; } try { $flickr = new Zend_Service_Flickr($this->apikey); $results = $flickr->tagSearch($keywords, array( 'per_page' => $amount, 'tag_mode' => 'all', 'license' => 3 )); if($results->totalResults() > 0) { return $results; } } catch (Zend_Service_Exception $e) { return null; } return null; } } and this is the part of my controller that should deal with caching the result: $frontendOptions = array( 'lifetime' => 300, 'automatic_serialization' => true ); $backendOptions = array( 'cache_dir' => ROOT_DIR . '/var/cache/' ); $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions); if(!$results = $cache->load('flickr')) { $flickr = new Flickr; $results = $flickr->search($article->keywords); if($results != null) { $cache->save($results, 'flickr'); } } $this->view->flickr = $results; When there is no cache, the images show up without any problem. In my cache directory, two files are created: - zend_cache---flickr - zend_cache---internal-metadatas---flickr However, when reloading my page, and thus trying to get the data out of the cache, no images show up. When I print_r($this->result) in my view, I allways get the same array: Zend_Service_Flickr_ResultSet Object ( [totalResultsAvailable] => 139778 [totalResultsReturned] => 6 [firstResultPosition] => 1 [_results:protected] => DOMNodeList Object ( ) [_flickr:private] => Zend_Service_Flickr Object ( [apiKey] => XXXX_API_KEY_XXXX [_restClient:protected] => Zend_Rest_Client Object ( [_data:protected] => Array ( ) [_uri:protected] => Zend_Uri_Http Object ( [_username:protected] => [_password:protected] => [_host:protected] => www.flickr.com [_port:protected] => 80 [_path:protected] => /services/rest/ [_query:protected] => [_fragment:protected] => [_regex:protected] => Array ( [escaped] => %[[:xdigit:]]{2} [unreserved] => [A-Za-z0-9-_.!~*'()\[\]] [segment] => (?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\]:@&=+$,;])* [path] => (?:\/(??:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\]:@&=+$,;])*)?)+ [uric] => (?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*'()\[\];\/?:@&=+$,]) ) [_scheme:protected] => http ) ) ) [_currentIndex:private] => 0 ) ... but the images just don't show up. Now, I am figuring that there might be some kind of problem with the serialization/unserialization of the Flickr object. Zend_Cache works fine - tried a string and an array. Any clues why the images just don't show up ? Thanks a lot in advance freaks ! dGo Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/ Share on other sites More sharing options...
dgoosens Posted December 3, 2009 Author Share Posted December 3, 2009 Hi guys, Nobody has a clue ? thanks once more ! Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970298 Share on other sites More sharing options...
448191 Posted December 3, 2009 Share Posted December 3, 2009 I see _results is a DOMNodeList. That is an internal structure that wont serialize. You'll have to fetch the results in the resultset into a serializable composite, like an array or object of a userland class. Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970447 Share on other sites More sharing options...
dgoosens Posted December 3, 2009 Author Share Posted December 3, 2009 thanks a lot for your reply 448191 So, if I am getting this right, I should, within my Flickr class, convert the $result into an array... Would that work ? I guess I could iterate through the DOMNodeList and insert all the data into an array... or would there be some toArray() method that I could use for this ? Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970454 Share on other sites More sharing options...
448191 Posted December 3, 2009 Share Posted December 3, 2009 thanks a lot for your reply 448191 So, if I am getting this right, I should, within my Flickr class, convert the $result into an array... Would that work ? I guess I could iterate through the DOMNodeList and insert all the data into an array... or would there be some toArray() method that I could use for this ? Yes and I don't know. But I assume you're smart enough to figure it out from here, if not you can send me a PM and we can discuss my hourly rate. Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970498 Share on other sites More sharing options...
dgoosens Posted December 3, 2009 Author Share Posted December 3, 2009 [...]if not you can send me a PM and we can discuss my hourly rate. I was only asking for advice... I thought this was the purpose of this forum... I did not ask you to write one single line of code did I... but thanks anyway... Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970501 Share on other sites More sharing options...
448191 Posted December 3, 2009 Share Posted December 3, 2009 It was a joke. Meant to illustrate that since I don't know the specific API heart, and you are currently working on it, you looking it up would be quicker than me looking it up and you waiting until I have an answer. Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970505 Share on other sites More sharing options...
dgoosens Posted December 3, 2009 Author Share Posted December 3, 2009 oh OK... lol - sorry... I am trying to figure this out while doing the job that I am payed for, which has nothing to do with PHP and is rather boring right now... I'll post my solution when I'll have one. Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970510 Share on other sites More sharing options...
dgoosens Posted December 3, 2009 Author Share Posted December 3, 2009 well... finally got to the real business... (not at work anymore) Thus, I changed the $result of my Flickr class into an array and now the Zend_Cache is working... and serializing the data correctly. Here is my new class: class Flickr { protected $apikey; public function __construct() { $this->apikey = Zend_Registry::get('config')->flickr_api_key; } public function search($keywords, $amount = 6) { if(empty ($this->apikey)) { return null; } try { $flickr = new Zend_Service_Flickr($this->apikey); $results = $flickr->tagSearch($keywords, array( 'per_page' => $amount, 'tag_mode' => 'all', 'license' => 3 )); if($results->totalResults() > 0) { foreach ($results as $key => $value) { $resultsArray[$key] = $value; } return $resultsArray; } } catch (Zend_Service_Exception $e) { return null; } return null; } } I just had to change one line in my view... but it is working great now. Thanks a lot for your help 448191 ! dGo Quote Link to comment https://forums.phpfreaks.com/topic/183772-zend_cache-and-zend_service_flickr/#findComment-970645 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.