-2

我希望将我的数组键的值回显到该控制器的视图中。我无法完全弄清楚。因此,对于第一个提要,我想将 mmafighting 回显到视图中。然后它将遍历其余部分。

这是我的控制器代码:

function index()
{
$this->load->library('simplepie');
       $feeds = array('mmafighting' => 'http://www.mmafighting.com/rss/current',
                    'bbc' => 'http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml',
                    'bloodyelbow' => 'http://www.bloodyelbow.com/rss',
                    'ufc' => 'http://www.ufc.com/rss/news',
                    'hackernews' => 'http://news.ycombinator.com/rss',
                    'msnbc' => 'http://www.msn.com/rss/news.aspx',
                    'msnbc2' => 'http://www.msn.com/rss/msnmoney.aspx',
                    'msnbc3' => 'http://www.msn.com/rss/msnshopping_top.aspx'

                 );
    foreach ($feeds as $site=>$url)
    {
        $data['feed'][$site] = new SimplePie();
        $data['feed'][$site]->set_feed_url($url);
        $data['feed'][$site]->set_cache_location(APPPATH.'cache');
        $data['feed'][$site]->set_cache_duration(300);
        $data['feed'][$site]->init();
        $data['feed'][$site]->handle_content_type();
    }
    $this->load->view('feedsview', $data);
}

这是我的视图代码:

<?php
$feedCount = 0; 
$rowCount = 0;
?>
<?php foreach ($feed as $site): ?>

    <?php if ($site->data): ?>
            <div class="feed">
            <h2><?php // echo original array key here ?></h2>
            <ul>
            <?php $items = $site->get_items(0, 5); ?>
            <?php foreach ($items as $item): ?>
                <li><a href="<?php echo $item->get_link(); ?>"><?php echo $item->get_title(); ?></a></li>
            <?php endforeach; ?>
        </ul>
        </div>
        <?php endif; ?>



<?php $feedCount++; ?>
<?php if ($feedCount === 3) {
    echo '<div style="clear:both;">&nbsp;</div>';
    $feedCount = 0;
    $rowCount++;
        if ($rowCount === 2) {
            echo '<div style="width:1000px; margin-bottom:20px;height:100px; border:1px solid #252525; float:left;">images</div>';
            }
    } ?>
    <?php endforeach; ?>
4

1 回答 1

1

我不确定我是否理解,但如何做到这一点:

<?php foreach ($feed as $key => $site): ?>

    <?php if ($site->data): ?>
            <div class="feed">
            <h2><?php echo $key ?></h2>
            <ul>
于 2012-04-27T20:26:42.647 回答