我似乎无法解决这个问题。我想从 RSS 文件中获取媒体:缩略图。使用 ZF2 ; Zend\Frame a 遵循手册,但我无法从 xml 文件中获取图像,任何想法请 :)
Controller 代码:
<?php
namespace RSS\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Feed\Reader as feed;
class IndexController extends AbstractActionController
{
public function indexAction(){
try{
$rss = feed\Reader::import('http://www.wdcdn.net/rss/presentation/library/client/skunkus/id/cc3d06c1cc3834464aef22836c55d13a');
}catch (feed\Exception\RuntimeException $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.php 添加一个名为 getMedia() 的新函数来解决它,对于谁有更好的想法或更好的代码,我将如有帮助,不胜感激:
public function getMedia()
{
if (array_key_exists('media', $this->data)) {
return $this->data['media'];
}
$media = null;
if ($this->getType() == Reader\Reader::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'];
}
关于php - 使用 zend 2 feed 解析 RSS 文件,我无法获取媒体标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20662622/