从带有详细信息的JSON中加载模块


Loading modules from JSON with details

我有一个函数,应该从json文件加载模块。下面是函数:

$json = file_get_contents("modules.json");
$modules =json_decode($json, true);
foreach ($modules as $module) {
    include('include/scripts/' . $module);
}

JSON:

["gallery.class.php", "blog.class.php", "members.class.php"]

这个功能可以工作,但我希望它有更多的细节,像天气它是启用或不,和一个描述,等

您最好的选择可能是将json设置为数组 [] 或对象 {}

看起来像这样:

[
    {
        "name": "gallery",
        "description": "DESCRIPTION",
        "link": "gallery.class.php"
    },
    {
        "name": "Blog",
        "description": "DESCRIPTION",
        "link": "blog.class.php"
    },
    {
        "name": "Members",
        "description": "DESCRIPTION",
        "link": "members.class.php"
    }
]

在php代码中你只需要循环遍历json数据作为items

$json = file_get_contents("modules.json");
$modules =json_decode($json, true);
foreach ($modules as $module) {
    include('include/scripts/' . $module['link']);
}