Yii整合ZF2中Feed模块

 Yii1 整合ZF2的Feed模块
  • * \ZendFramework-2.4.9.zip\ZendFramework-2.4.9\library\Zend * 的文件夹拷贝到 Yii1 的项目工程中的 * \YiiProject\protected\vendor *

  • Controller 中的 Action 实例的示范代码。


    public function actionFeedReader() {
        Yii::import('application.vendor.*');
        Yii::setPathOfAlias('Zend',Yii::getPathOfAlias('application.vendor.Zend'));

        $url = 'http://news.yahoo.co.jp/pickup/rss.xml';
        $reader = Zend\Feed\Reader\Reader::import($url);

        header("Content-Type: text/html; charset=UTF-8");
        echo '<pre>' . print_r($reader, true) . '</pre>';
    }


    public function actionFeedWriter() {
        Yii::import('application.vendor.*');
        Yii::setPathOfAlias('Zend',Yii::getPathOfAlias('application.vendor.Zend'));

        $feed = new Zend\Feed\Writer\Feed;
        $feed->setTitle('Paddy\'s Blog');
        $feed->setLink('http://www.example.com');
        $feed->setFeedLink('http://www.example.com/atom', 'atom');
        $feed->addAuthor(array(
            'name'  => 'Paddy',
            'email' => 'paddy@example.com',
            'uri'   => 'http://www.example.com',
        ));
        $feed->setDateModified(time());
        $feed->addHub('http://pubsubhubbub.appspot.com/');

        /**
         * Add one or more entries. Note that entries must
         * be manually added once created.
         */
        $entry = $feed->createEntry();
        $entry->setTitle('All Your Base Are Belong To Us');
        $entry->setLink('http://www.example.com/all-your-base-are-belong-to-us');
        $entry->addAuthor(array(
            'name'  => 'Paddy',
            'email' => 'paddy@example.com',
            'uri'   => 'http://www.example.com',
        ));
        $entry->setDateModified(time());
        $entry->setDateCreated(time());
        $entry->setDescription('Exposing the difficultly of porting games to English.');
        $entry->setContent(
            'I am not writing the article. The example is long enough as is ;).'
        );
        $feed->addEntry($entry);

        /**
         * Render the resulting feed to Atom 1.0 and assign to $out.
         * You can substitute "atom" with "rss" to generate an RSS 2.0 feed.
         */

        header('Content-Type: application/xml');
        $out = $feed->export('atom');
        echo $out;
    }

Yii 2.0: Integrating ZF2 into Yii - use case demonstrated
Zend\Feed\Writer\Writer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值