Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To get around that you can get the current document and then load the <code>module</code> renderer. e.g. if I wanted the Latest news module I had setup with a title of "Sport News" I could use this:</p> <pre class="lang-php prettyprint-override"><code>$module = 'mod_articles_latest'; $title = 'Sport News'; $document = JFactory::getDocument(); $renderer = $document-&gt;loadRenderer('module'); $theModule = JModuleHelper::getModule($module, $title); </code></pre> <p>So, to handle the case where modules aren't assigned to the current or all menu items you could possibly create your own helper that inherits from <code>JModuleHelper</code> and override <em>just</em> the protected function <code>_load()</code>.</p> <pre><code>class MyModuleHelper extends JModuleHelper { protected static function &amp;_load() { static $clean; if (isset($clean)) { return $clean; } $Itemid = JRequest::getInt('Itemid'); $app = JFactory::getApplication(); $user = JFactory::getUser(); $groups = implode(',', $user-&gt;getAuthorisedViewLevels()); $lang = JFactory::getLanguage()-&gt;getTag(); $clientId = (int) $app-&gt;getClientId(); $cache = JFactory::getCache('com_modules', ''); $cacheid = md5(serialize(array($Itemid, $groups, $clientId, $lang))); if (!($clean = $cache-&gt;get($cacheid))) { $db = JFactory::getDbo(); $query = $db-&gt;getQuery(true); $query-&gt;select('m.id, m.title, m.module, m.position, m.content, m.showtitle, m.params, mm.menuid'); $query-&gt;from('#__modules AS m'); $query-&gt;join('LEFT', '#__modules_menu AS mm ON mm.moduleid = m.id'); $query-&gt;where('m.published = 1'); $query-&gt;join('LEFT', '#__extensions AS e ON e.element = m.module AND e.client_id = m.client_id'); $query-&gt;where('e.enabled = 1'); $date = JFactory::getDate(); $now = $date-&gt;toSql(); $nullDate = $db-&gt;getNullDate(); $query-&gt;where('(m.publish_up = ' . $db-&gt;Quote($nullDate) . ' OR m.publish_up &lt;= ' . $db-&gt;Quote($now) . ')'); $query-&gt;where('(m.publish_down = ' . $db-&gt;Quote($nullDate) . ' OR m.publish_down &gt;= ' . $db-&gt;Quote($now) . ')'); $query-&gt;where('m.access IN (' . $groups . ')'); $query-&gt;where('m.client_id = ' . $clientId); // Disable this line in your override class's _load()... // $query-&gt;where('(mm.menuid = ' . (int) $Itemid . ' OR mm.menuid &lt;= 0)'); // Filter by language if ($app-&gt;isSite() &amp;&amp; $app-&gt;getLanguageFilter()) { $query-&gt;where('m.language IN (' . $db-&gt;Quote($lang) . ',' . $db-&gt;Quote('*') . ')'); } $query-&gt;order('m.position, m.ordering'); // Set the query $db-&gt;setQuery($query); $modules = $db-&gt;loadObjectList(); $clean = array(); if ($db-&gt;getErrorNum()) { JError::raiseWarning(500, JText::sprintf('JLIB_APPLICATION_ERROR_MODULE_LOAD', $db-&gt;getErrorMsg())); return $clean; } // Apply negative selections and eliminate duplicates $negId = $Itemid ? -(int) $Itemid : false; $dupes = array(); for ($i = 0, $n = count($modules); $i &lt; $n; $i++) { $module = &amp;$modules[$i]; // The module is excluded if there is an explicit prohibition $negHit = ($negId === (int) $module-&gt;menuid); if (isset($dupes[$module-&gt;id])) { // If this item has been excluded, keep the duplicate flag set, // but remove any item from the cleaned array. if ($negHit) { unset($clean[$module-&gt;id]); } continue; } $dupes[$module-&gt;id] = true; // Only accept modules without explicit exclusions. if (!$negHit) { // Determine if this is a 1.0 style custom module (no mod_ prefix) // This should be eliminated when the class is refactored. // $module-&gt;user is deprecated. $file = $module-&gt;module; $custom = substr($file, 0, 4) == 'mod_' ? 0 : 1; $module-&gt;user = $custom; // 1.0 style custom module name is given by the title field, otherwise strip off "mod_" $module-&gt;name = $custom ? $module-&gt;module : substr($file, 4); $module-&gt;style = null; $module-&gt;position = strtolower($module- &gt;position); $clean[$module-&gt;id] = $module; } } unset($dupes); // Return to simple indexing that matches the query order. $clean = array_values($clean); $cache-&gt;store($clean, $cacheid); } return $clean; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload