以编程方式向Joomla添加文章 [英] Programmatically adding an article to Joomla

查看:134
本文介绍了以编程方式向Joomla添加文章的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Joomla还是陌生的(坦率地说,刚开始探索使用Joomla的可能性),并且需要以编程方式向Joomla后端表添加文章的帮助(请参阅下面的详细信息).同样,我想了解这些列的值应该如何:

I am very new to Joomla (frankly just started exploring the possibility of using Joomla) and need help with programmatically adding articles to Joomla backend tables (please see details below). Also along the same lines, I would like to understand how should values for the columns:

  • parent_id
  • lft
  • rgt
  • 级别

以及它们的功能是什么(例如,它们是指针/索引"还是类似于os inode来唯一标识文件,还是它们具有更多的功能属性?例如识别类别,子类别等)

be generated for the table jos_assets (#__assets) and what is their functional role (eg are they "pointers/indexes" analogous to, say, an os inode to uniquely indentify a file or are they more functional attributes such as identifying the category, subcategory etc)

使用下面的简化示例来说明我正在尝试做的事情可能会有所帮助.假设我们有一个程序可以收集各种关键信息,例如网络文章作者的姓名,文章的主题类型,文章的日期以及文章的链接.我希望能够扩展该程序,以编程方式在Joomla中存储此信息.当前,此信息存储在自定义表中,并且用户可以通过自定义php网页在一定日期范围内使用以作者姓名为单位的搜索条件来查找感兴趣的文章.然后显示搜索结果以及指向实际文章的超链接.文章存储在本地Web服务器上,不是外部链接.自定义表中存储的超链接部分包括物理文档的相对路径(相对于Web根目录),例如:

It might help to use the following SIMPLIFIED example to illustrate what I am trying to do. Say we have a program that collects various key information such as names of the authors of web articles, the subject type of the articles, the date of articles as well as a link to the article. I want to be able to extend this program to programmatically store this information in Joomla. Currently this information is stored in a custom table and the user, through a custom php web page, can use search criteria say by author name, over a certain range of dates to find the article(s) of interest. The result of this search is then displayed along with a hyperlink to the actual article. The articles are stored locally on the web server and are not external links. The portion of the hyperlink stored in the custom table includes the relative path of the physical document (relative to the web root), so for example:

Author   date         type    html_file
Tom      08-14-2011   WEB     /tech/11200/ar_324.html
Jim      05-20-2010   IND     /tech/42350/ar_985.html

凭借Joomla在编写自定义php搜索和演示页面以及趋势分析等方面提供的所有优势,我们真的想切换到它.似乎在其他表格中,例如,可以通过编程方式填充#__assets#__content,以便从我们现有的php程序(用于编译数据)中填充Joomla,然后使用Joomla.

With all the advantages that Joomla offers over writing custom php search and presentation pages as well as trending etc, we would really like to switch to it. It seems that among other tables for example that #__assets and #__content can be populated programmatically to populate Joomla from our existing php program (which is used to compile the data) and then use Joomla.

任何示例,建议和帮助都将不胜感激

Any examples, suggestions and help is greatly appreciated

最诚挚的问候 加尔(Gar)

Kindest regards Gar

推荐答案

仅作初步说明:Joomla 1.6/1.7非常相似. 1.5没那么多.我假设使用1.6/1.7,因为这是我建议作为新项目的基础.

Just an initial note: Joomla 1.6/1.7 are pretty similar. 1.5 not so much. I'll assume 1.6/1.7, as that's what I'd recommend as a base for a new project.

首先,您需要运行对Joomla框架的访问权限.您可以通过组件,模块或引导它的cron或任何其他方式执行此操作.我不会去做的.

First up, you'll need to be running with access to the Joomla framework. You could do this through a Component, or a module, or a cron that bootstraps it or whatever. I won't go though how to do that.

但是,一旦您这样做,创建一篇文章就相当简单了.

But once you do that, creating an article is reasonably simple.

<?php
require_once JPATH_ADMINISTRATOR . '/components/com_content/models/article.php';

$new_article = new ContentModelArticle();

$data = array(
    'catid' => CATEGORY_ID,
    'title' => 'SOME TITLE',
    'introtext' => 'SOME TEXT',
    'fulltext' => 'SOME TEXT',
    'state' => 1,
);
$new_article->save($data);

实际的字段列表会比实际的字段列表长一些(必填字段等),但是您应该从Joomla框架中获得合理的错误消息等,以阐明这一点.

The actual list of fields will be a bit longer than that (required fields etc), but you should get sane error messages etc from the Joomla framework which illuminate that.

总而言之:

  • 加载Joomla框架,以便您可以访问数据库,组件,模型等
  • 包括com_content文章类,该类将进行验证,为您保存到数据库等
  • 使用适当的必填字段创建文章实例
  • 致电save()

现在我考虑一下,它可能会在1.5中工作...

Now that I think about it, that'll probably work in 1.5...

这篇关于以编程方式向Joomla添加文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆