使用 zend 2 提要解析 RSS 文件,我无法获得媒体标签



我似乎无法解决这个问题。我想从 RSS 文件中获取媒体:缩略图。使用 ZF2 ;Zend\Frame a 按照手册进行操作,但我无法从 xml 文件中获取图像,任何想法请:)

控制器代码:

<?php
namespace RSSController;
use ZendMvcControllerAbstractActionController;
use ZendViewModelViewModel;
use ZendFeedReader as feed;
class IndexController extends AbstractActionController
{
    public function indexAction(){
        try{
            $rss =            feedReader::import('http://www.wdcdn.net/rss/presentation/library/client/skunkus/id/cc3d06c1cc3834464aef22836c55d13a');
        }catch (feedExceptionRuntimeException $e){
            echo "error : " . $e->getMessage();
            exit;
        }
       $channel = array(
            'title'       => $rss->getTitle(),
            'description' => $rss->getDescription(),
            'link'        => $rss->getLink(),
            'items'       => array()
        );
        foreach($rss as $item){
            $channel['items'][] = array(
                'title'       => $item->getTitle(),
                'link'        => $item->getLink(),
                'description' => $item->getDescription(),
               // 'image'       => $item->getImage(),
            );
        }
        return new  ViewModel(array(
            'channel' => $channel
        ));
    }

}

对于谁得到相同的 pb,我通过向 Zend/Feed/Reader/Entry/rss 添加一个名为 getMedia() 的新功能来解决它.php谁有更好的想法或更好的代码,如果您提供帮助,我将不胜感激:

    public function getMedia()
{
    if (array_key_exists('media', $this->data)) {
        return $this->data['media'];
    }
    $media = null;
    if ($this->getType() == ReaderReader::TYPE_RSS_20) {
        $nodeList = $this->xpath->query($this->xpathQueryRss . '/media:thumbnail');
        if ($nodeList->length > 0) {
            $media = new stdClass();
            $media->url    = $nodeList->item(0)->getAttribute('url');
        }
    }
    $this->data['media'] = $media;
    return $this->data['media'];
}

这是一种无需扩展或修改类即可执行此操作的方法:

foreach ($channel as $item) {
    $xmlItem = $item->saveXml();
    $xmlFeed = new SimpleXMLElement($xmlItem);
    $thumbAttr = $xmlFeed->children('http://search.yahoo.com/mrss/')->thumbnail->attributes();
    $thumbUrl = (string)$thumbAttr['url'];
}

最新更新