以编程方式将文章添加到 Joomla

发布于 2024-11-29 04:45:57 字数 993 浏览 2 评论 0原文

我对 Joomla 非常陌生(坦率地说,我刚刚开始探索使用 Joomla 的可能性),并且需要帮助以编程方式将文章添加到 Joomla 后端表(请参阅下面的详细信息)。同样,我想了解如何

  • 列的值: parent_id
  • lft
  • rgt
  • level

为表 jos_assets (#__assets) 生成 以及它们的值是什么功能角色(例如,它们是类似于唯一标识文件的操作系统索引节点的“指针/索引”,还是它们更具功能属性,例如标识类别、子类别等)

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

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

等等。

与编写自定义 php 搜索和演示页面相比,Joomla 提供的所有优势以及趋势等,我们真的很想切换到它。似乎在其他表中,例如 #__assets#__content 可以通过编程方式填充,以从我们现有的 php 程序(用于编译数据)填充 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
  • level

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)

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

etc.

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

Kindest regards
Gar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾城如夢未必闌珊 2024-12-06 04:45:57

初步说明:Joomla 1.6/1.7 非常相似。 1.5 没那么多。我假设 1.6/1.7,因为这是我推荐的新项目的基础。

首先,您需要能够访问 Joomla 框架。您可以通过组件、模块、引导它的 cron 或其他任何方式来完成此操作。我不会去想如何做到这一点。

但一旦你这样做了,创建一篇文章就相当简单了。

<?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 框架中获得合理的错误消息等来说明这一点。

总之:

  • 加载 Joomla 框架,以便您可以访问数据库、组件、模型等
  • 包含 com_content 文章类,它将为您处理验证、保存到数据库等 创建
  • 一个填写了必填字段的文章实例酌情调用
  • save()

现在我想了一下,这可能会在 1.5 中起作用......

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.

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);

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.

So in summary:

  • Load up the Joomla framework so you have access to the DB, components, models, etc
  • Include the com_content article class, which will handle validation, saving to the database etc for you
  • Create an article instance with the required fields filled in as appropriate
  • Call save()

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

不…忘初心 2024-12-06 04:45:57

找到了一种更好的方法来做到这一点,没有任何错误 创建 Joomla!以编程方式文章

$table = JTable::getInstance('Content', 'JTable', array());

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

// Bind data
if (!$table->bind($data))
{
    $this->setError($table->getError());
    return false;
}

// Check the data.
if (!$table->check())
{
    $this->setError($table->getError());
    return false;
}

// Store the data.
if (!$table->store())
{
    $this->setError($table->getError());
    return false;
}

Found a better way to do this without any errors Create a Joomla! Article Programatically

$table = JTable::getInstance('Content', 'JTable', array());

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

// Bind data
if (!$table->bind($data))
{
    $this->setError($table->getError());
    return false;
}

// Check the data.
if (!$table->check())
{
    $this->setError($table->getError());
    return false;
}

// Store the data.
if (!$table->store())
{
    $this->setError($table->getError());
    return false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文