开发者

Easy way to get "params" from Joomla menu table

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=
f开发者_JAVA技巧usion_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?


Right way is to use JMenu::getParams method

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


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


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜