获取对象的属性

时间:2014-03-22 14:28:21

标签: php joomla

所以如果我在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

谢谢! 戴夫

1 个答案:

答案 0 :(得分:0)

params字段看起来像json数据,json对象是精确的,因为它包含在{}中,所以为了使它在PHP中可用,试试这个

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

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