用的是thinkphp框架,现在要引用config.json文件,
config.json文件里面就是普通的json格式
{
"imageActionName": "uploadimage",
"imageUrl": "/BeRetailer/RetailerBrand/uploadImg",
"imageFieldName": "file",
"imageMaxSize": 2048000,
"imageAllowFiles": [
".png",
".jpg",
".jpeg",
".gif",
".bmp"
]
}
现在imageUrl的值怎么才能动态的从controller中传,我这样写,他不能转译
"imageUrl": "{$imageUrl}"
怎么才是正确的格式?
$json = require('config.json');
$arr = json_decode($json,true);
Convert json to array
json_decode
If it is a configuration file, according to common sense, the configuration file is equivalent to a constant and generally will not be modified dynamically. If it needs to be modified dynamically, then these data are not suitable for configuration files.
If you must modify it, you can use config.php. Why use config.json? json is suitable for node.
Dynamic modification of files requires php file operation function, take a look at the
fopen()
和fwrite()
functionTwo suggestions
Write this json directly into the template file. This way we can parse this variable
Write imageurl into array form
"imageActionName": "uploadimage",
"imageUrl": [
"/BeRetailer/RetailerBrand/uploadImg",
"/BeRetailer/RetailerBrand/uploadImg2",
"/BeRetailer/RetailerBrand/uploadImg3"],
"imageFieldName" : "file",
"imageMaxSize": 2048000,
"imageAllowFiles": [
]
//In this way, when using this json, just pass the url k directly from the controller