0

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);
Community
  • 1
  • 1
  • Try $table->id, after you store table with $table->store(); – di3sel Mar 10 '14 at 13:59
  • if (!$table->store()) { $this->setError($table->getError()); return false; This returns JTableContent. I am new to programming. I know this is not the correct way. $table->id; echo $table; – user2549928 Mar 10 '14 at 14:37
  • Happy I could help, don't forget to vote up my answer and check it as answered below :) – di3sel Mar 10 '14 at 17:22

1 Answers1

0

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)

di3sel
  • 2,002
  • 15
  • 24