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 = '*';
// 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

This prints out the created object which looks ok, but it then just throws:


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.

  • 1
    Have you looked at packages? They allow you to install multiple extensions at once. This may be an idea for you if your module doesn't contain any dynamic data. – Lodder May 20 '19 at 8:31
  • I have it set up as a package and it installs the module but I want to create 4 of the same module in the module manager. So I'm trying to replicate programatically the user going to module manager and then adding 4 instances of the installed module. – user1616338 May 20 '19 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.