我正在尝试从Joomla的菜单表中获取参数.我在下面的工作是在返回参数的意义上.
$menu = &JSite::getMenu();
$item = $menu->getItem($menuId)->params;
print $items;
Run Code Online (Sandbox Code Playgroud)
但是,它以纯文本形式返回它们,好像我刚刚查询了列并返回了params内容.
有人可以告诉我如何将其作为对象或数组返回,以便我可以使用类似的东西:
$myParam = $item->getParams('theParamIwant');
Run Code Online (Sandbox Code Playgroud)
xad*_*ict 12
我认为JParameter在Joomla已经过时了!3.x,所以答案现在是这样的:
$app = JFactory::getApplication();
$menuitem = $app->getMenu()->getActive(); // get the active item
$menuitem = $app->getMenu()->getItem($theid); // or get item by ID
$params = $menuitem->params; // get the params
print_r($params); // print all params as overview
Run Code Online (Sandbox Code Playgroud)
您可以menu_image通过执行以下操作获取变量:
echo $params->get('menu_image');
Run Code Online (Sandbox Code Playgroud)
或者首先检查它是否已填写,如果是,echo则:
// using get() with a second parameter makes it fall back to this if nothing is found
$menu_image = $params->get('menu_image', false);
if ($menu_image && strlen($menu_image) {
echo "<img src='$menu_image'/>";
}
Run Code Online (Sandbox Code Playgroud)
或者,使用tertiary运营商:
$menuimg = $params->get('menu_image')
echo strlen($menuimg) ? "<img src='$menuimg'/>" : '';
Run Code Online (Sandbox Code Playgroud)
小智 8
您需要使用JParameter类来读取参数.尝试这样的事情:
$item = $menu->getItem($menuId);
$params = new JParameter($item->params);
$myParam = $params->get('theParamIwant');
| 归档时间: |
|
| 查看次数: |
18847 次 |
| 最近记录: |