I want to create and install a module via component postflight. I can get postflight etc. to work, but I can't get it to create and install the module.
Code I've created:
// 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
$module = JTable::getInstance('Module');
$module->extension = 'mod_w4cmenu';
$module->title = 'My New Menu';
$module->description = 'A module for my component';
$module->published = 1;
$module->access = 1;
$module->params = '{"title":"menu2","cssPrefix":"","menuText":"New TExt","includeButton":"0"}';
$module->metadata = '{"page_title":"","author":"","robots":""}';
$module->language = '*';
echo"<pre>";
print_r($module);
echo"</pre>";
// Set the location in the tree
//$module->setLocation(1, 'last-child');
// Check to make sure our data is valid
if (!$module->check())
{
JError::raiseNotice(500, $module->getError());
return false;
}
// Now store the category
if (!$module->store(true))
{
JError::raiseNotice(500, $module->getError());
return false;
}
// Build the path for our category
$module->rebuildPath($module->id);
This prints out the created object which looks ok, but it then just throws:
Error
I could believe that I'm completely off track with the way I'm implementing this, but I can't find anything that explains how to do this.