在Joomla! 1.5下,JDocuemntFeed帮助我们完成了很多工作,实现自己Joomla!组件的Feed相对更为简单。我们只需要在自己的组件的某个视图下目录下添加一个新文件view.feed.php ,比如我们的示例是com_test组件test视图,我们要在com_test/views/test/目录下,新增一个文件view.feed.php ,具体代码如下:
<?php
jimport( 'joomla.application.component.view');
class TestViewTest extends JView
{
function display($tpl = null)
{
global $mainframe;
$db =& JFactory::getDBO();
$doc =& JFactory::getDocument();
$params =& $mainframe->getParams();
JRequest::setVar('limit', $mainframe->getCfg('feed_limit'));
$item = new JFeedItem();
$item->title = 'test title';
$item->link = 'http://www.maycode.com';
$item->description = 'test description';
$item->date = date('r',time());
$item->category = 'test category';
$doc->addItem( $item );
}
}
?>
现在你就可以通过 http://yourdomain.com/index.php?option=com_test&view=test&format=feed&type=rss来访问了。变换type=rss为type=atom就支持 atom格式输出了。
我们这里只是一个示例,实际你应该循环将视图对应table取得的数据都添加到$doc的RSS数组中。