「php入門」Zend Framework Feedの読み込む

1.IndexControllerコード
<?php

class IndexController extends Zend_Controller_Action {

public function init() {
/* Initialize action controller here */
}

public function indexAction() {
$allnewsUrl = 'http://rss.XXX.XXX.XXX/news/allnews/auto.xml’;
$guideUrl = 'http://rss.XXX.XXX.XXX/auto/guide/index.xml’;
$tUrl = 'http://rss.XXX.XXX.XXX/auto/news/t/index.xmll’;
$newcarUrl = 'http://rss.XXX.XXX.XXX/auto/newcar/index.xml’;
$eUrl = 'http://rss.XXX.XXX.XXX/auto/news/e/index.xml’;
$salesUrl = 'http://rss.XXX.XXX.XXX/auto/sales/index.xml’;
$recallsUrl = 'http://rss.XXX.XXX.XXX/auto/recalls/index.xml’;
$servicingUrl = 'http://rss.XXX.XXX.XXX/auto/servicing/index.xml’;
$insuranceUrl = 'http://rss.XXX.XXX.XXX/auto/insurance/index.xml’;
$ultratuneUrl = 'http://rss.XXX.XXX.XXX/auto/ultratune/index.xml’;
$automotiveUrl = 'http://rss.XXX.XXX.XXX/auto/automotive/index.xml’;
$trafficUrl = 'http://rss.XXX.XXX.XXX/auto/traffic/index.xml’;
$tireUrl = 'http://rss.XXX.XXX.XXX/auto/tire/index.xml’;
$allnewsList = $this->rssreaderAction($allnewsUrl);
$guideList = $this->rssreaderAction($guideUrl);
$tList = $this->rssreaderAction($tUrl);
$newcarList = $this->rssreaderAction($newcarUrl);
$eList = $this->rssreaderAction($eUrl);
$salesList = $this->rssreaderAction($salesUrl);
$recallsList = $this->rssreaderAction($recallsUrl);
$servicingList = $this->rssreaderAction($servicingUrl);
$insuranceList = $this->rssreaderAction($insuranceUrl);
$ultratuneList = $this->rssreaderAction($ultratuneUrl);
$automotiveList = $this->rssreaderAction($automotiveUrl);
$trafficList = $this->rssreaderAction($trafficUrl);
$tireList = $this->rssreaderAction($tireUrl);
$this->view->allnewsList = $allnewsList;
$this->view->guideList = $guideList;
$this->view->tList = $tList;
$this->view->newcarList = $newcarList;
$this->view->eList = $eList;
$this->view->salesList = $salesList;
$this->view->recallsList = $recallsList;
$this->view->servicingList = $servicingList;
$this->view->insuranceList = $insuranceList;
$this->view->ultratuneList = $ultratuneList;
$this->view->automotiveList = $automotiveList;
$this->view->trafficList = $trafficList;
$this->view->tireList = $tireList;
}

public function rssreaderAction($uri) {
$rssArray = array();
try {

$rssreader = Zend_Feed::import($uri);
} catch (Zend_Feed_Exception $e) {
echo “Feed異常:$e->getMessage()\n";
exit();
}
foreach ($rssreader->items as $item) {
$rssArray[] = array(
'title’ => $item->title(),
'link’ => $item->link(),
'description’ => $item->description(),
);
}
return $rssArray;
}

}
2.ファイル名:index.phtml
サンプルコード:
<div id="container">
<div id="left">
<div id="recommend" class="box">
<ul>
<?php foreach ($this->allnewsList as $allnews): ?>
<li><a href="<?php echo $this->escape($allnews['link’]); ?>" target="_blank" title="<?php echo $this->escape($allnews['title’]); ?>"><?php echo $this->escape($allnews['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="blogs" class="box">
<ul>
<?php foreach ($this->guideList as $guide): ?>
<li><a href="<?php echo $this->escape($guide['link’]); ?>" target="_blank" title="<?php echo $this->escape($guide['title’]); ?>"><?php echo $this->escape($guide['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="jobs" class="box">
<ul>
<?php foreach ($this->tList as $t): ?>
<li><a href="<?php echo $this->escape($t['link’]); ?>" target="_blank" title="<?php echo $this->escape($t['title’]); ?>"><?php echo $this->escape($t['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div id="content">
<div id="news">
<ul>
<?php foreach ($this->newcarList as $newcar): ?>
<li><a href="<?php echo $this->escape($newcar['link’]); ?>" target="_blank" title="<?php echo $this->escape($newcar['title’]); ?>"><?php echo $this->escape($newcar['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->eList as $e): ?>
<li><a href="<?php echo $this->escape($e['link’]); ?>" target="_blank" title="<?php echo $this->escape($e['title’]); ?>"><?php echo $this->escape($e['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->salesList as $sales): ?>
<li><a href="<?php echo $this->escape($sales['link’]); ?>" target="_blank" title="<?php echo $this->escape($sales['title’]); ?>"><?php echo $this->escape($sales['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="picture">
<ul>
<?php foreach ($this->recallsList as $recalls): ?>
<li><a href="<?php echo $this->escape($recalls['link’]); ?>" target="_blank" title="<?php echo $this->escape($recalls['title’]); ?>"><?php echo $this->escape($recalls['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->servicingList as $servicing): ?>
<li><a href="<?php echo $this->escape($servicing['link’]); ?>" target="_blank" title="<?php echo $this->escape($servicing['title’]); ?>"><?php echo $this->escape($servicing['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->insuranceList as $insurance): ?>
<li><a href="<?php echo $this->escape($insurance['link’]); ?>" target="_blank" title="<?php echo $this->escape($insurance['title’]); ?>"><?php echo $this->escape($insurance['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="topic">
<ul>
<?php foreach ($this->ultratuneList as $ultratune): ?>
<li><a href="<?php echo $this->escape($ultratune['link’]); ?>" target="_blank" title="<?php echo $this->escape($ultratune['title’]); ?>"><?php echo $this->escape($ultratune['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->automotiveList as $automotive): ?>
<li><a href="<?php echo $this->escape($automotive['link’]); ?>" target="_blank" title="<?php echo $this->escape($automotive['title’]); ?>"><?php echo $this->escape($automotive['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
<ul>
<?php foreach ($this->trafficList as $traffic): ?>
<li><a href="<?php echo $this->escape($traffic['link’]); ?>" target="_blank" title="<?php echo $this->escape($traffic['title’]); ?>"><?php echo $this->escape($traffic['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div id="right">
<div id="groups">
<ul>
<?php foreach ($this->tireList as $tire): ?>
<li><a href="<?php echo $this->escape($tire['link’]); ?>" target="_blank" title="<?php echo $this->escape($tire['title’]); ?>"><?php echo $this->escape($tire['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="rules">
<ul>
<?php foreach ($this->allnewsList as $allnews): ?>
<li><a href="<?php echo $this->escape($allnews['link’]); ?>" target="_blank" title="<?php echo $this->escape($allnews['title’]); ?>"><?php echo $this->escape($allnews['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
<div id="goods">
<ul>
<?php foreach ($this->allnewsList as $allnews): ?>
<li><a href="<?php echo $this->escape($allnews['link’]); ?>" target="_blank" title="<?php echo $this->escape($allnews['title’]); ?>"><?php echo $this->escape($allnews['title’]); ?></a></li>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>

Development

Posted by arkgame