获取对象的属性

模板博客

因此,如果我在Joomla中使用以下代码

jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules( 'nav' );
echo '<pre>';
print_r( $modules );
echo '</pre>';

返回以下内容:

Array
(
    [0] => stdClass Object
        (
            [id] => 1
            [title] => Main Menu
            [module] => mod_menu
            [position] => nav
            [content] => 
            [showtitle] => 0
            [params] => {"menutype":"mainmenu","base":"","startLevel":"1","endLevel":"0","showAllChildren":"1","tag_id":"","class_sfx":"","window_open":"","layout":"joomberui:TopNav","moduleclass_sfx":" contain-to-grid","cache":"1","cache_time":"900","cachemode":"itemid","module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}
            [menuid] => 0
            [name] => menu
            [style] => 
        )

)

如果我添加,echo $modules[0]->params->menu;那么我只会得到参数

我只会得到moduleclass_sfx什么?

谢谢!戴夫

里格斯愚蠢

params字段看起来像json数据,这是一个精确包装在其中的json对象{}因此要使其在PHP中可用,请尝试以下操作

$params = json_decode($modules[0]->params);

echo 'moduleclass_sfx = ' . $params->moulesclass_sfx;

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章