Atom Feedを出力 | zend framework
http://framework.zend.com/manual/1.11/en/zend.feed.html
http://framework.zend.com/manual/1.11/en/zend.feed.consuming-atom.html
http://framework.zend.com/manual/1.11/en/zend.feed.writer.html
atom feedを出力します。
// 空のfeedを作成
$feed = new Zend_Feed_Writer_Feed;
$feed->setTitle(‘blog.bbtune’);
$feed->setLink(‘http://blog.bbtune.com’);
$feed->setFeedLink(‘http://blog.bbtune.com/atom’, ‘atom’);
$feed->addAuthor(array(
‘name’ => ‘Junichi Otake’,
‘uri’ => ‘http://blog.bbtune.com’,
));
$feed->setDateModified(time());
// エントリーを追加
$entry = $feed->createEntry();
$entry->setTitle(‘create an atom feed’);
$entry->setLink(‘http://blog.bbtune.com/’);
$entry->addAuthor(array(
‘name’ => ‘Junichi Otake’,
‘uri’ => ‘http://blog.bbtune.com’,
));
$entry->setDateModified(time());
$entry->setDateCreated(time());
$entry->setDescription(‘generated a feed by zend framework zend_feed_writer’);
$entry->setContent(‘generated a feed by zend framework zend_feed_writer’);
$feed->addEntry($entry);
$feed = new Zend_Feed_Writer_Feed;
$feed->setTitle(‘blog.bbtune’);
$feed->setLink(‘http://blog.bbtune.com’);
$feed->setFeedLink(‘http://blog.bbtune.com/atom’, ‘atom’);
$feed->addAuthor(array(
‘name’ => ‘Junichi Otake’,
‘uri’ => ‘http://blog.bbtune.com’,
));
$feed->setDateModified(time());
// エントリーを追加
$entry = $feed->createEntry();
$entry->setTitle(‘create an atom feed’);
$entry->setLink(‘http://blog.bbtune.com/’);
$entry->addAuthor(array(
‘name’ => ‘Junichi Otake’,
‘uri’ => ‘http://blog.bbtune.com’,
));
$entry->setDateModified(time());
$entry->setDateCreated(time());
$entry->setDescription(‘generated a feed by zend framework zend_feed_writer’);
$entry->setContent(‘generated a feed by zend framework zend_feed_writer’);
$feed->addEntry($entry);
// 出力
$out = $feed->export(‘atom’);
実行したらまさかのエラー
PHP Fatal error: Class ‘DOMDocument’ not found in Zend/Feed/Writer/Renderer/Feed/Atom.php on line 73
http://www.php.net/manual/ja/dom.requirements.php
yum install php-xml
outを出力すると
<?xml version=”1.0″ encoding=”UTF-8″?>
<feed xmlns=”http://www.w3.org/2005/Atom”>
<title type=”text”>blog.bbtune</title>
<updated>2012-06-26T17:04:26+09:00</updated>
<generator uri=”http://framework.zend.com” version=”1.11.6″>Zend_Feed_Writer</generator>
<link rel=”alternate” type=”text/html” href=”http://blog.bbtune.com”/>
<link rel=”self” type=”application/atom+xml” href=”http://blog.bbtune.com/atom”/>
<id>http://blog.bbtune.com</id>
<author>
<name>Junichi Otake</name>
<uri>http://blog.bbtune.com</uri>
</author>
<entry xmlns:xhtml=”http://www.w3.org/1999/xhtml”>
<title type=”html”><![CDATA[create an atom feed]]></title>
<summary type=”html”><![CDATA[generated a feed by zend framework zend_feed_writer]]></summary>
<published>2012-06-26T17:04:26+09:00</published>
<updated>2012-06-26T17:04:26+09:00</updated>
<link rel=”alternate” type=”text/html” href=”http://blog.bbtune.com/”/>
<id>http://blog.bbtune.com/</id>
<author>
<name>Junichi Otake</name>
<uri>http://blog.bbtune.com</uri>
</author>
<content xmlns:xhtml=”http://www.w3.org/1999/xhtml” type=”xhtml”>
<xhtml:div xmlns:xhtml=”http://www.w3.org/1999/xhtml”>generated a feed by zend framework zend_feed_writer</xhtml:div>
</content>
</entry>
</feed>
<feed xmlns=”http://www.w3.org/2005/Atom”>
<title type=”text”>blog.bbtune</title>
<updated>2012-06-26T17:04:26+09:00</updated>
<generator uri=”http://framework.zend.com” version=”1.11.6″>Zend_Feed_Writer</generator>
<link rel=”alternate” type=”text/html” href=”http://blog.bbtune.com”/>
<link rel=”self” type=”application/atom+xml” href=”http://blog.bbtune.com/atom”/>
<id>http://blog.bbtune.com</id>
<author>
<name>Junichi Otake</name>
<uri>http://blog.bbtune.com</uri>
</author>
<entry xmlns:xhtml=”http://www.w3.org/1999/xhtml”>
<title type=”html”><![CDATA[create an atom feed]]></title>
<summary type=”html”><![CDATA[generated a feed by zend framework zend_feed_writer]]></summary>
<published>2012-06-26T17:04:26+09:00</published>
<updated>2012-06-26T17:04:26+09:00</updated>
<link rel=”alternate” type=”text/html” href=”http://blog.bbtune.com/”/>
<id>http://blog.bbtune.com/</id>
<author>
<name>Junichi Otake</name>
<uri>http://blog.bbtune.com</uri>
</author>
<content xmlns:xhtml=”http://www.w3.org/1999/xhtml” type=”xhtml”>
<xhtml:div xmlns:xhtml=”http://www.w3.org/1999/xhtml”>generated a feed by zend framework zend_feed_writer</xhtml:div>
</content>
</entry>
</feed>
終わり。