1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Remove "setNested" from config

Discussion in 'Development' started by McpeBooster, May 26, 2017.

  1. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    How can I remove a line from a config if I have set it with "setNested" before? When I try to remove it does not work
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    What have you tried?
     
  3. McpeBooster

    McpeBooster Baby Zombie

    Messages:
    190
    GitHub:
    mcpebooster
    $config->remove("test.2");
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    when you set the variable as nested, you basically made an array. use this to help you:
    PHP:
    if(isset($config->getAll()[$key])) {
        
    $arr $config->getAll();
        unset(
    $arr[$key]);
        
    $config->setAll($arr);
    }
    $key is what comes before the .
    $config is an instance of Config
     
    SOFe likes this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note that setNested() and getNested() are made for real config files that are used for configuration, not for saving data, and hence usually one wouldn't want to remove an attribute from a config file.
     
    jasonwynn10 and Sandertv like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.