如何在Joomla中获取文章ID文章提交

时间:2014-03-10 13:41:52

标签: php joomla article

我能够以编程方式创建Joomla文章。感谢以下帖子。 Create a Joomla! Article Programatically

该文章已成功创建,但现在我想要捕获新创建的Joomla文章的文章ID或文章网址。

这个想法是,一旦注册用户创建了一篇文章,用户就会收到一封电子邮件,其中包含他/她创建的文章的完整URL。

- 如果可以提取文章ID,我可以使用index.php?option = com_content& view = article& id = XXX 要么 - 如果可以取出完整的SEF URL,那就很棒了

代码片段如下

else {
        $table = JTable::getInstance('Content', 'JTable', array());
        $data = array(
            'catid' => $category,
            'title' => $msgbody,
            'fulltext' => $button,
            'publish_down' => $sixdate,
            'state' => 1,
            'metakey' => $meta,
            'metadesc' => $msgbody,
            'ips' => $ip,
        );

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

        if (!$table->check())
        {
            $this->setError($table->getError());
            return false;
        }

        if (!$table->store())
        {
            $this->setError($table->getError());
            return false;
        }

        $mailer = JFactory::getMailer();
        $config = JFactory::getConfig();
        $sender = array( 
            $config->getValue( 'config.mailfrom' ),
            $config->getValue( 'config.fromname' ) );

        $mailer->setSender($sender);

        $user = JFactory::getUser();
        $urecipient = $user->email;

        $mailer->addRecipient($urecipient);

1 个答案:

答案 0 :(得分:0)

根据我在代码中看到的内容,您可以使用$table->id(使用$table->store();方法后)存储后访问文章ID;

构建sef URL的最简单方法是使用本机文章路由构建器:

require_once(JPATH_ROOT . '/components/com_content/helpers/route.php');
$link = JRoute::_(ContentHelperRoute::getArticleRoute($table->id, $table->catid);

($ table-> catid param是可选的)

相关问题