gpt4 book ai didi

php - 从 Joomla 获取菜单参数

转载 作者:可可西里 更新时间:2023-11-01 13:34:34 25 4
gpt4 key购买 nike

我正在尝试从 Joomla 的菜单表中获取参数。我下面的内容在返回参数的意义上是有效的。

 $menu =   &JSite::getMenu();
$item = $menu->getItem($menuId)->params;
print $items;

但是,它以纯文本形式返回它们,就好像我刚刚查询了该列并返回了参数内容一样。

谁能告诉我如何将其作为对象或数组返回,以便我可以使用类似的东西:

$myParam = $item->getParams('theParamIwant');

最佳答案

我认为 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

您可以通过以下方式获取 menu_image 变量:

 echo $params->get('menu_image');

或者首先检查它是否被填充,如果是,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'/>";
}

或者,使用第三级运算符:

$menuimg = $params->get('menu_image')
echo strlen($menuimg) ? "<img src='$menuimg'/>" : '';

关于php - 从 Joomla 获取菜单参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4972811/

25 4 0