Can I set value like Settings::set('some-variable','hello')?

As if we can get value using Settings::get('some-variable') then why the 'set' method is not working?

  • The reason you can't set settings is that settings is a read-only wrapper of things defined in settings.php. You can't rewrite that from code, you actually need to do it by changing $settings.php. – Berdir Jul 5 '16 at 18:30

No, you can not call Settings::set. You should get an

Error: Call to undefined method Drupal\Core\Site\Settings::set() in ...

Maybe there's something wrong with your error reporting or you imported any other Settings class (check your namespace). Check your php.ini for this. The Settings Class is for read-only access to the settings in settings.php.

If you need to set some system settings do it like this:

// themes
->set('admin', 'bartik')

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.