返回顶部

收藏

Zend Framework Feed

更多

Zend Framework Feed

IndexController

<?php

class IndexController extends Zend_Controller_Action {

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

    public function indexAction() {
        $allnewsUrl = 'http://rss.sina.com.cn/news/allnews/auto.xml';
        $guideUrl  = 'http://rss.sina.com.cn/auto/guide/index.xml';
        $tUrl  = 'http://rss.sina.com.cn/auto/news/t/index.xmll';
        $newcarUrl  = 'http://rss.sina.com.cn/auto/newcar/index.xml';
        $eUrl  = 'http://rss.sina.com.cn/auto/news/e/index.xml';
        $salesUrl  = 'http://rss.sina.com.cn/auto/sales/index.xml';
        $recallsUrl  = 'http://rss.sina.com.cn/auto/recalls/index.xml';
        $servicingUrl  = 'http://rss.sina.com.cn/auto/servicing/index.xml';
        $insuranceUrl  = 'http://rss.sina.com.cn/auto/insurance/index.xml';
        $ultratuneUrl  = 'http://rss.sina.com.cn/auto/ultratune/index.xml';
        $automotiveUrl  = 'http://rss.sina.com.cn/auto/automotive/index.xml';
        $trafficUrl  = 'http://rss.sina.com.cn/auto/traffic/index.xml';
        $tireUrl  = 'http://rss.sina.com.cn/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;
    }

}

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>

标签:Zend,Framework

收藏

0人收藏

支持

0

反对

0

发表评论