thinkphp怎么动态赋予config.json的值?
世界只因有你
世界只因有你 2017-05-16 13:10:54
0
4
381

用的是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}"
怎么才是正确的格式?

世界只因有你
世界只因有你

reply all(4)
左手右手慢动作

$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()function

Ty80

Two suggestions

  1. Write this json directly into the template file. This way we can parse this variable

  2. 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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!