简体   繁体   English

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

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

I am able to create Joomla articles programatically. 我能够以编程方式创建Joomla文章。 Thanks to the below post. 感谢下面的帖子。 Create a Joomla! 创建一个Joomla! Article Programatically 以编程方式撰写文章

The article is created successfully but now I want to capture the article id or the article url of the newly created Joomla article. 文章创建成功,但是现在我想捕获新创建的Joomla文章的文章ID或文章url。

The idea is that once a registered user creates an article, the user will receive an email with the complete URL of the article that he/she has created. 这个想法是,一旦注册用户创建了文章,该用户将收到一封电子邮件,其中包含他/她创建的文章的完整URL。

-If the article ID can be fetched out, I can use index.php?option=com_content&view=article&id=XXX OR - If the complete SEF URL can be fetched out then it will be great -如果可以提取文章ID,则可以使用index.php?option = com_content&view = article&id = XXX或-如果可以提取完整的SEF URL,那就太好了

snippet of the code is as follows 代码片段如下

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

From what i see in code, you can access article id after storing by using $table->id (after using $table->store(); method); 根据我在代码中看到的内容,可以在存储后使用$table->id (在使用$table->store();方法之后)访问商品ID。

The easiest way to build sef URL is to use native article route builder: 建立sef URL的最简单方法是使用本机文章路由生成器:

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

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

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

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