AnswerBun.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!

Related Questions

Generating a module instance from PHP

0  Asked on September 5, 2021 by ffrewin

   

Embed custom JS app in Joomla MVC

0  Asked on September 5, 2021 by miasto

     

Error when updating Gantry from 4.1.20 to 4.1.32

1  Asked on September 5, 2021 by norberto-gomes

       

Change user permissions programmatically on the fly

1  Asked on September 5, 2021 by aheavyobject

   

Akeeba backup update broke the site

2  Asked on September 5, 2021 by hamlet-kraskian

   

Proper way for autoloading in Joomla 4

1  Asked on September 5, 2021 by webchun

     

Menu Specifically For Super Users

1  Asked on September 5, 2021

       

Joomla PHP does not match host PHP

2  Asked on February 18, 2021

     

Controller Joomla – Output Class construct for color css style

1  Asked on February 5, 2021 by andrea-suriani

       

Joomla custom component – router not find alias

1  Asked on January 21, 2021 by lecraver

     

Joomla 3 call model function inside controller

3  Asked on December 28, 2020 by wbdevlop

   

Product url problem after updating VirtueMart

1  Asked on December 23, 2020 by kiasaty

     

Display intro image inside mod_breadcrumbs

0  Asked on November 11, 2020 by geoplous

   

Ask a Question

Get help from others!

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