Magento 2 class constructorDynamically instanciate class with argumentswhen to use di.xml for my custom...
Why Normality assumption in linear regression
What happens to output if OPAMP its supply is tweaked?
Can I write a book of my D&D game?
Can a hotel cancel a confirmed reservation?
Who is this Ant Woman character in this image alongside the Wasp?
How would an AI self awareness kill switch work?
Why has the mole been redefined for 2019?
What is the wife of a henpecked husband called?
How to limit sight distance to 1 km
Using only 1s, make 29 with the minimum number of digits
How should I handle players who ignore the session zero agreement?
Could a phylactery of a lich be a mirror or does it have to be a box?
Which one of these password policies is more secure?
Program that converts a number to a letter of the alphabet
Table formatting top left corner caption
What is this metal M-shaped device for?
Traveling through the asteriod belt?
Why is mind meld hard for T'pol in Star Trek: Enterprise?
Why do members of Congress in committee hearings ask witnesses the same question multiple times?
One Half of Ten; A Riddle
How do you funnel food off a cutting board?
Would a National Army of mercenaries be a feasible idea?
Why do stocks necessarily drop during a recession?
Writing a character who is going through a civilizing process without overdoing it?
Magento 2 class constructor
Dynamically instanciate class with argumentswhen to use di.xml for my custom module class?Where are class constructor parameters defined in Magento2?Constructor integrity testsAnnoyed by tons of classes for DI in constructors of Magento 2 - is there a better way?Why some classes define injections in both their constructor and di.xml?Dependency Injection and constructor parametersMagento2: Checking if a module exists, after being injected via class constructorMagento 2: Use a model with a dynamic name through DIMagento 2 create objectGet system config values in magento 2 without constructor
I have class in my module for Magento 2.
His constructor gets 2 parameters
class MyClass
{
private $str1;
private $str2;
public function __construct(string $str1, string str2)
{
$this->str1 = $str1;
$this->str2 = $str2;
}
}
This parameters saved in database in core_config_data
table.
I want use this class in other module classes, but i dont know how i can use DI for object transfer of this class in constructors others classes.
I can use for this di.xml
?
magento2 database di core-config-data
add a comment |
I have class in my module for Magento 2.
His constructor gets 2 parameters
class MyClass
{
private $str1;
private $str2;
public function __construct(string $str1, string str2)
{
$this->str1 = $str1;
$this->str2 = $str2;
}
}
This parameters saved in database in core_config_data
table.
I want use this class in other module classes, but i dont know how i can use DI for object transfer of this class in constructors others classes.
I can use for this di.xml
?
magento2 database di core-config-data
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
I can create object through$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento
– Akolzin Dmitry
Apr 3 '18 at 14:04
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago
add a comment |
I have class in my module for Magento 2.
His constructor gets 2 parameters
class MyClass
{
private $str1;
private $str2;
public function __construct(string $str1, string str2)
{
$this->str1 = $str1;
$this->str2 = $str2;
}
}
This parameters saved in database in core_config_data
table.
I want use this class in other module classes, but i dont know how i can use DI for object transfer of this class in constructors others classes.
I can use for this di.xml
?
magento2 database di core-config-data
I have class in my module for Magento 2.
His constructor gets 2 parameters
class MyClass
{
private $str1;
private $str2;
public function __construct(string $str1, string str2)
{
$this->str1 = $str1;
$this->str2 = $str2;
}
}
This parameters saved in database in core_config_data
table.
I want use this class in other module classes, but i dont know how i can use DI for object transfer of this class in constructors others classes.
I can use for this di.xml
?
magento2 database di core-config-data
magento2 database di core-config-data
edited 53 mins ago
Muhammad Hasham
2,0141424
2,0141424
asked Apr 3 '18 at 10:31
Akolzin DmitryAkolzin Dmitry
63
63
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
I can create object through$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento
– Akolzin Dmitry
Apr 3 '18 at 14:04
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago
add a comment |
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
I can create object through$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento
– Akolzin Dmitry
Apr 3 '18 at 14:04
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
I can create object through
$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento– Akolzin Dmitry
Apr 3 '18 at 14:04
I can create object through
$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento– Akolzin Dmitry
Apr 3 '18 at 14:04
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f220854%2fmagento-2-class-constructor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f220854%2fmagento-2-class-constructor%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hard to understand the question, can you give more specific example?
– Eugene Tulika
Apr 3 '18 at 12:39
class ObserverClass extends Observer { public function __construct (MyClass $ myclass) {} }
– Akolzin Dmitry
Apr 3 '18 at 13:57
For example exist observer class and I want use my class in observer, like this. But dependency injection will not create this object, as dont know what parameters must get my class
– Akolzin Dmitry
Apr 3 '18 at 14:01
I can create object through
$myclass = new MyClass($str1, $str2);
but this a bad practice in Magento– Akolzin Dmitry
Apr 3 '18 at 14:04
Please visit: magento.stackexchange.com/questions/147366/… this may help you
– iqbal malik
32 mins ago