The thinkphp framework is used. Now we need to reference the config.json file.
The config.json file contains the ordinary json format
{
"imageActionName": "uploadimage",
"imageUrl": "/BeRetailer/RetailerBrand/uploadImg",
"imageFieldName": "file",
"imageMaxSize": 2048000,
"imageAllowFiles": [
".png",
".jpg",
".jpeg",
".gif",
".bmp"
]
}
Now how can the value of imageUrl be dynamically transferred from the controller? If I write it like this, it cannot be translated
"imageUrl": "{$imageUrl}"
What is the correct format?
ringa_lee2017-05-16 13:12:54
$json = require('config.json');
$arr = json_decode($json,true);
Convert json to array
仅有的幸福2017-05-16 13:12:54
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()
function
PHP中文网2017-05-16 13:12:54
Two 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": [
".png",
".jpg",
".jpeg",
".gif",
".bmp"
]
//In this way, when using this json, just pass the url k directly from the controller