Php 如何在Joomla提交文章后获得文章ID

Php 如何在Joomla提交文章后获得文章ID,php,joomla,article,Php,Joomla,Article,我能够以编程方式创建Joomla文章。感谢下面的帖子。 文章创建成功,但现在我想捕获新创建的Joomla文章的文章id或文章url 这个想法是,一旦注册用户创建了一篇文章,用户将收到一封电子邮件,其中包含他/她创建的文章的完整URL -如果可以提取文章ID,我可以使用index.php?option=com\u content&view=article&ID=XXX 或 -如果完整的SEF URL可以取出,那么它将是伟大的 代码片段如下 else { $table = JTab

我能够以编程方式创建Joomla文章。感谢下面的帖子。

文章创建成功,但现在我想捕获新创建的Joomla文章的文章id或文章url

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

-如果可以提取文章ID,我可以使用index.php?option=com\u 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);

从我在代码中看到的情况来看,您可以使用
$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参数是可选的)

使用$table->store()存储表格后,请尝试$table->id;如果(!$table->store()){$this->setError($table->getError());返回false;返回JTableContent。我是编程新手。我知道这不是正确的方法。$table->id;echo$table;很有效。非常感谢。很高兴我能提供帮助,别忘了投票支持我的答案,并按下面的答案检查:)