Easy way to get “params” from Joomla menu table

放肆的年华 提交于 2019-12-11 05:31:32

问题


I don't know too much about Joomla, but I'm trying to work with a Menu on a Joomla site. In the Database I can see a column called params in the menu table, and it has some data I need. The params column has this data:

categories=446
feedLink=1
fusion_item_subtext=
fusion_columns=1
fusion_customimage=
splitmenu_item_subtext=
page_title=
show_page_title=1
pageclass_sfx=
menu_image=-1
secure=0

I know I can do a mysql query, get that column and parse the value using string manipulation/regex, but that doesn't sound like the right way.

I have seen some code in Joomla that looks like:

$cid = $params->get('secure');

Does Joomla have a special way to query and return objects so that these params are accessible with this type of syntax?


回答1:


Yes, Joomla does have special way of getting the parameters in an easily accessible object based on JObject.

you can get the entire site menu with this

$menu = JFactory::getApplication()->getMenu();
$item = $menu->getActive(); // will get active menu item. can use getItem() instead to get specific item
$item->get('parmName'); 

This is not exact code, more like pseudocode. This will get you on the right track...

Helpfull Stuff:

  • Joomla Framework API
  • JMenu Documentation



回答2:


Right way is to use JMenu::getParams method

$app =& JFactory::getApplication();
$menu =& $app->getMenu();
$params = $menu->getParams($menuItemId);
$params->get('paramName');



回答3:


first you get a JApplication instance like this

$app = & JFactory::getApplication();

or for joomla 1.5 use:

global $mainframe //to get JApplication object

get JMenu instance like this:

$menu = $app->getMenu();

you can get active menu params or any other menu params like this

$active = $menu->getActive(); //get active menu
$menuInstance = $menu->getActive($Itemid); // to get Itemid use JRequest::getInt('Itemid', 0);

here you have an StdClass object with params field inside, now u use JParameter class like this

$menuParams = new JParameter($menuInstance->params);

here you have it, to get any parameter you want:

$someParam = $menuParams->get('some_param', 'default');


来源:https://stackoverflow.com/questions/4957889/easy-way-to-get-params-from-joomla-menu-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!