2

I want to access a component variable (a simple array) from a module without using session (no persistence across page loads necessary in my case), JRequest/JInput, global, plugin nor model. Is it possible to use JDocumentHTML's setBuffer/getBuffer something like below?

In my my_component_view.php

$doc =& JFactory::getDocument();
$doc->setBuffer( implode(",",$cat_lists), 'module', 'my_cat_lists' );

And in my_module_view.php

$doc =& JFactory::getDocument();
$buffer = $doc->getBuffer('module', 'my_cat_lists');        
$cat_lists = explode(",",$buffer);

It's a hacky workaround though. Wonder what would be the best approach.

  • 1
    Why don't you want to use JInput? – Craig Aug 24 '15 at 0:38
  • I would say the best approach for this would be to use a session – Lodder Aug 24 '15 at 9:17
  • Where is the component getting $cat_lists? It should come derivated from an input and maybe after some calculations it produce $cat_List. You can made a function for this calculation apply it in the component then also in the module – Piero Marsilio Sep 17 '15 at 14:55
  • @Piero , the fact is, I don't want to query, populate or calculate the $cat_lists two times individually in component and module to be shown on the same page. – kolunar Sep 18 '15 at 4:23
  • 1
    Hi, it may seem repeated work, but if this calculation is done by a function in the model or in a helper, and the query is the same, it would be cached. Really it is nanoseconds to recalculate and you have a cleaner more robust solution than trying to pass a variable – Piero Marsilio Sep 18 '15 at 6:25