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.

9
  • What are you trying to accomplish? The documentation linked is for Joomla\CMS\Menu\MenuItem but you're manipulating Joomla\CMS\Application\SiteApplication.
    – Sharky
    Commented Jan 7, 2019 at 9:24
  • I want to concatenate something to the page class. I see it in the JFactory get application.
    – Eoin
    Commented Jan 7, 2019 at 10:55
  • Where is your code located? In a plugin?
    – Sharky
    Commented Jan 8, 2019 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
    Commented Jan 9, 2019 at 8:45
  • 1
    See documentation docs.joomla.org/Plugin/Events/System.
    – Sharky
    Commented Jan 10, 2019 at 7:46

2 Answers 2

2

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);
}
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);
2
  • 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
    Commented Jan 6, 2019 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
    Commented Jul 26, 2019 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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