Skip to content

Instantly share code, notes, and snippets.

@javigomez
Forked from mbabker/gist:3211464
Created October 22, 2012 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javigomez/3931973 to your computer and use it in GitHub Desktop.
Save javigomez/3931973 to your computer and use it in GitHub Desktop.
Creating a category via component postflight
// Get the database object
$db = JFactory::getDbo();
// JTableCategory is autoloaded in J! 3.0, so...
if (version_compare(JVERSION, '3.0', 'lt'))
{
JTable::addIncludePath(JPATH_PLATFORM . 'joomla/database/table');
}
// Initialize a new category
$category = JTable::getInstance('Category');
$category->extension = 'com_myextension';
$category->title = 'My Category';
$category->description = 'A category for my extension';
$category->published = 1;
$category->access = 1;
$category->params = '{"target":"","image":""}';
$category->metadata = '{"page_title":"","author":"","robots":""}';
$category->language = '*';
// Set the location in the tree
$category->setLocation(1, 'last-child');
// Check to make sure our data is valid
if (!$category->check())
{
JError::raiseNotice(500, $category->getError());
return false;
}
// Now store the category
if (!$category->store(true))
{
JError::raiseNotice(500, $category->getError());
return false;
}
// Build the path for our category
$category->rebuildPath($category->id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment