Joomla!-开源天空

2008-12-05
首页 专栏热点 Joomla! 源代码分析 给自己开发的Joomla!组件增加RSS


给自己开发的Joomla!组件增加RSS

E-mail

在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数组中。

相关文章:
一个在文章正文中显示幻灯的插件
这篇关于Joomla! unit testing 的文章值得看
怎样创建一个Joomla! 1.5 新用户
如何修改mod_latestnews模块以显示文章的发布日期
如何给Joomla!组件扩展添加PDF
如何在Joomla!管理后台中添加自定义的按钮
给自己的Joomla!组件扩展添加参数
如何在Joomla!组件扩展中添加验证码captcha,程序修改篇
怎样强制自己退出登陆状态
如何在Joomla!组件扩展中添加验证码captcha,服务器配置篇


收藏此文章:
Digg! Reddit! Del.icio.us! JoomlaVote! Google! Live! Facebook! StumbleUpon! Yahoo! Free social bookmarking plugins and extensions for Joomla! websites!

发表您的文章评论

您的姓名 (昵称)
标题:
评分: 很差一般较好很好
评论:
验证码:
请输入验证码