简体   繁体   中英

How to get article ID post article submission in Joomla

I am able to create Joomla articles programatically. Thanks to the below post. Create a 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.

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.

-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

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

The easiest way to build sef URL is to use native article route builder:

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

($table->catid param is optional)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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