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 '
' . print_r($reader, true) . '
'
; } 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' => '[email protected]', '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' => '[email protected]', '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

你可能感兴趣的:(PHP)