繁体   English   中英

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

[英]How to get article ID post article submission in Joomla

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

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

这个想法是,一旦注册用户创建了文章,该用户将收到一封电子邮件,其中包含他/她创建的文章的完整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);

根据我在代码中看到的内容,可以在存储后使用$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是可选的)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM