Hello everyone;
I have a chronoform form that post the post data into a file called JOOMLA_DIR/scripts/req.php.
The problem is that i don't know how to create an article into a specific category id, lets suppose it 49. My joomla version is 2.5.
This is the code i tested, so i did remove the $_POST variables only to make the code more easy to analyse.
Thank you for your help.
I have a chronoform form that post the post data into a file called JOOMLA_DIR/scripts/req.php.
The problem is that i don't know how to create an article into a specific category id, lets suppose it 49. My joomla version is 2.5.
This is the code i tested, so i did remove the $_POST variables only to make the code more easy to analyse.
Thank you for your help.
<?php
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__)));
require_once(JPATH_BASE.'/includes/defines.php');
require_once(JPATH_BASE.'/includes/framework.php');
require_once(JPATH_BASE.'/libraries/joomla/factory.php');
if (!defined('DS')) {
define('DS', DIRECTORY_SEPARATOR);
}
require_once(JPATH_BASE.'/libraries/joomla/application/component/helper.php');
jimport('joomla.application.component.modeladmin');
require_once(JPATH_COMPONENT_ADMINISTRATOR.'/helpers/content.php');
require_once(JPATH_ADMINISTRATOR.'/components/com_content/models/article.php');
/*
$new_article = new ContentModelArticle();
$data = array(
'catid' => 49,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
$new_article->save($data);*/
$table = JTable::getInstance('content', 'JTable');
$data = array(
'catid' => 49,
'title' => 'SOME TITLE',
'introtext' => 'SOME TEXT',
'fulltext' => 'SOME TEXT',
'state' => 1,
);
// Bind data
if (!$table->bind($data))
{
$this->setError($table->getError());
return false;
}
// Check the data.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// Store the data.
if (!$table->store())
{
$this->setError($table->getError());
return false;
}
?>