What is the best way to pass some not predifined string to model construct in Magento 2 with di.xml? I have an api class which requires incoming params like service url, login and license key which i want to take from config section.

  • Can't you just inject in your class and instance of the config model and then read the values from the config? – Marius Feb 23 '15 at 15:03
  • Yes it is possible, but i want to keep api class independent from config class and just pass required information to construct. – Rostyslav Redko Feb 23 '15 at 15:42
  • I'm not 100% sure but I think you cannot inject a dynamic value through di.xml. From my point of view, if you need in your class a value from config, this means that your class depends on the config class. But I may be wrong. – Marius Feb 23 '15 at 15:58

The correct answer would be, you dont do this. You have at least a data Object.

But Maybe you are more searching for the Configuration parts already existent in Magento1. You can use them like here and like in Magento1 you can create a default entry for this configs, so you dont need to add a real input field in the system config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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