Forums

JTable content + another table

peers 16 Feb, 2010
Hi,

I'm trying to write to two tables, jos_content, and also jos_jreviews_content (the second one needs the lastid to get the contentid or id as its called in jos_content.

Throwing a lot of errors back when trying to write to jos_content using queries, so i tried to copy the autogenerated code accross from the submitcontent example download, into the form code submit before email on my form.
$_POST['catid'] = '9';
$_POST['id'] = '';
$_POST['sectionid'] = '3';
$_POST['state'] = '0';
$_POST['created'] = date("Y-m-d H:i:s");

$MyForm =& CFChronoForm::getInstance();
$user = JFactory::getUser();			
$row =& JTable::getInstance("content", "Table");
srand((double)microtime()*10000);
$inum	=	"I" . substr(base64_encode(md5(rand())), 0, 16).md5(uniqid(mt_rand(), true));
JRequest::setVar( "recordtime", JRequest::getVar( "recordtime", date("Y-m-d")." - ".date("H:i:s"), "post", "string", "" ));
JRequest::setVar( "ipaddress", JRequest::getVar( "ipaddress", $_SERVER["REMOTE_ADDR"], "post", "string", "" ));
JRequest::setVar( "uid", JRequest::getVar( "uid", $inum, "post", "string", "" ));
JRequest::setVar( "cf_user_id", JRequest::getVar( "cf_user_id", $user->id, "post", "int", "" ));
$post = JRequest::get( "post" , JREQUEST_ALLOWRAW );			
if (!$row->bind( $post )) {
	JError::raiseWarning(100, $row->getError());
}				
if (!$row->store()) {
	JError::raiseWarning(100, $row->getError());
}
$MyForm->tablerow["jos_content"] = $row;

$lastId = $row->id;


it comes back with:

Fatal error: Call to a member function bind() on a non-object in /../components/com_chronocontact/libraries/customcode.php(61) : eval()'d code on line 30


do i need to include the fields into the code? i assumed as they are already named correctly in post data i wouldnt need to . Although they are amoungst a lot of other fields that will be used for the jreviews table.

Any idea what i might have missed?
GreyHead 16 Feb, 2010
Hi peers,

This line
$row =& JTable::getInstance("content", "Table");
gets the table info from a content table class. My guess is that you need some more code to load the JTable class.

Bob
peers 16 Feb, 2010
been trying to get this working for 3 or 4 days solid now with no luck,
tried:
jimport( 'joomla.database.table.content' );
JTable::addIncludePath(JPATH_COMPONENT.DS.'tables');


any ideas where im going wrong? joomla docs say use jimport, just doesnt seem to make any difference
GreyHead 16 Feb, 2010
Hi peers,

The include path for the content table isn't in the component (i.e. com_chronoforms). You'll need to get the correct path in there.

Bob
nml375 16 Feb, 2010
Hi peers,
You are using the incorrect table prefix. The default prefix for Joomla system tables is JTable.
Use either of the following lines instead:
$row =& JTable::getInstance("content");
// or
$row =& JTable::getInstance("content", "JTable");

You shouldn't have to worry about adding additional IncludePaths, since the JTableContent class file is in a known location, and the JTable::getInstance() classmethod will locate the file and load it as needed.

/Fredrik
This topic is locked and no more replies can be posted.