TransWikia.com

Generating a module instance from PHP

Joomla Asked by FFrewin on September 5, 2021

I am trying to render a mod_login module – on the fly – from inside a system plugin. So far, there is no existing mod_login instance in the website nor the database. I am just trying to create a new module object through PHP.

For the same 3.9.19 website, the following code works on my MAMP localhost with php72, but it doesn’t work on the online Litespeed server with php72.

$module = JModuleHelper::getModule('mod_login', '');
$moduleParams = new JRegistry($module->params);     
$moduleParams->set('style', "System-html5");
$module->showtitle = "1";
$module->title = $title;
$renderer = $doc->loadRenderer('module');
$modHtml = $renderer->render($module, array('params'=> $moduleParams));

On the online server, I have to create a login module and specifically select that one in order to render it, otherwise I am getting null params for the on-the-fly module and an empty string when it’s rendered.

$module = JModuleHelper::getModule('mod_login', 'My Login');

So are there any special conditions in order to generate a module this way?


###Some additional notes:

When online:
$module = JModuleHelper::getModule('mod_login', ''); :
If I have a mod_login module created and published in modules manager, then the above code will render that module. (haven’t tried with having 2 or more modules to see which one it will pick).

$module = JModuleHelper::getModule('mod_login', ''); :
With a trashed module, nothing will be rendered.

$module = JModuleHelper::getModule('mod_login'); :
Nothing will be rendered.

$module = JModuleHelper::getModule('mod_login', 'TEST'); :
With no mod_login module with that title, nothing will be rendered.

$module = JModuleHelper::getModule('mod_login', 'TEST'); :
With a mod_login module with that title, the TEST mod_login module will be rendered (and I assume it should also obey to any assignments like menu items/ACL that module will have).

On localhost:
$module = JModuleHelper::getModule('mod_login'); :
Will create a fresh mod_login instance, everything will work.

$module = JModuleHelper::getModule('mod_login', 'NON EXISTING MODULE TITLE'); :
Will create a fresh mod_login instance, everything will work.


Related content:

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP