Jtable::getInstance('category') is not working correctly

This forum is for general questions about extensions for Joomla! 2.5.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Sun Dec 05, 2010 2:57 am

Jtable::getInstance('category') is not working correctly

Post by rne1223 » Wed Feb 09, 2011 6:59 pm

Hello everyone, I been trying to create a component that adds multiple categories to the jos_categories table. Here is the base code that I'm using to add categories to the table:
$row =& JTable::getInstance('category');
$row->title = 'Hello world';
$row->path = 'helloworld';
$row->alias = 'helloworld';
$row->extension = 'com_content';
$row->level = 1;
$row->published = 1;
// Store the data if possible
JError::raiseError(500, 'Table store error: '.$table->getError());
return false;

Most the data gets store fine as you would expect but the 'level' and 'parent_id' doesn't update the default values. Does any of you know the reason? Has anyone found the solution to this problem?

Joomla! Ace
Joomla! Ace
Posts: 1964
Joined: Tue Jun 09, 2009 2:21 am
Location: WV

Re: Jtable::getInstance('category') is not working correctly

Post by jeffchannell » Sun Dec 04, 2011 8:12 am

Sorry to necro this thread but I came across it while searching for the same thing... which I finally found a solution for (after trudging through the code for JTableNested).

After your store() you have to "fix" the category:

Code: Select all

$row->moveByReference(0, 'last-child', $row->id);
EDIT: this worked for me when inserting a NEW category - YMMV for existing ones!
http://jeffchannell.com - Joomla Extensions & Support
http://biziant.com - Open Joomla Firewall/IDS
Unsolicited private messages/emails = hire me to fix your problem.

Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Tue Jul 26, 2011 6:55 am

Re: Jtable::getInstance('category') is not working correctly

Post by adamhudak » Mon Dec 05, 2011 7:37 am


how you create category from your component? I try create category in 'site' part like:

$table=& JTable::getInstance('category');

but it's return nothing. What do I wrong?

ok, i find what's wrong. And for everybody with same problem, just add:

Code: Select all

$path = JPATH_ADMINISTRATOR.DS."..".DS."libraries".DS."joomla".DS."database".DS."table";


Return to “Extensions for Joomla! 2.5”