search

Home  >  Q&A  >  body text

How does thinkphp dynamically assign the value to config.json?

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?

世界只因有你世界只因有你2782 days ago422

reply all(4)I'll reply

  • ringa_lee

    ringa_lee2017-05-16 13:12:54

    $json = require('config.json');

    $arr = json_decode($json,true);

    Convert json to array

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:12:54

    json_decode

    reply
    0
  • 仅有的幸福

    仅有的幸福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

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:12:54

    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

    reply
    0
  • Cancelreply