0

I'm trying to set one of my menu parameters. But I'm getting the error

0 CALL TO UNDEFINED METHOD JOOMLA\CMS\APPLICATION\SITEAPPLICATION::SETPARAMS()

My code is:

$app = JFactory::getApplication();
$app->setParams($appParams['pageclass_sfx'],$pageClass);

And I see setParams as an option in the API https://api.joomla.org/cms-3/classes/Joomla.CMS.Menu.MenuItem.html#method_setParams

I find the API quite difficult to understand without a relevant example. From searching the CMS code on GitHub I found this example:

function setParams($option, $param = false)
{
    return $this->IC->set_parameters($option, $param);
}

But that seems to confirm my code is written in the right way. In any case it seems to be saying the method doesn't exist.

  • What are you trying to accomplish? The documentation linked is for Joomla\CMS\Menu\MenuItem but you're manipulating Joomla\CMS\Application\SiteApplication. – Sharky Jan 7 at 9:24
  • I want to concatenate something to the page class. I see it in the JFactory get application. – Eoin Jan 7 at 10:55
  • Where is your code located? In a plugin? – Sharky Jan 8 at 10:00
  • 1
    onAfterRender is too late. It's used mainly to manipulate the already generated document. onAfterRoute would probably be most suitable in this case. – Sharky Jan 9 at 8:45
  • 1
    See documentation docs.joomla.org/Plugin/Events/System. – Sharky Jan 10 at 7:46
1

I don't think you should be trying to set the parameter through the JApplication object, but instead via the component helper, like so:

$menuParams = JComponentHelper::getParams('com_menus');
$menuParams->set('pageclass_sfx', $pageClass);
  • Ah I see. But when I do that I get Joomla\Registry\Registry::__set_state(array( 'data' => stdClass::__set_state(array( )), 'initialized' => false, 'separator' => '.', )); from my var_dump. Which doesn't include pageclass_sfx. – Eoin Jan 6 at 20:38
  • As a note to myself or others, if it is empty I don't think it is included in the array – Eoin Jul 26 at 10:32
1

There are two places where this could be set. The app params and the menu item params. Which ones would be used depends on how component is coded. See example how params are handled in article view https://github.com/joomla/joomla-cms/blob/57ca7a411fbeb3ec0c46594b1d4859c91c0b6a38/components/com_content/views/article/view.html.php#L73-L129.

To set a param in app:

$this->app->getParams()->set('pageclass_sfx', $pageClass);

To set a param for current menu item:

if ($menuItem = $this->app->getMenu()->getActive())
{
    $menuItem->params->set('pageclass_sfx', $pageClass);
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.