Magento 2 : Call Helper Without Using __construct in Own ModuleMandatory Helper class for module admin panel...
Can we use the stored gravitational potential energy of a building to produce power?
Dilemma of explaining to interviewer that he is the reason for declining second interview
Is there any other number that has similar properties as 21?
Parsing a string of key-value pairs as a dictionary
Is there any differences between "Gucken" and "Schauen"?
How can I deliver in-universe written lore to players without it being dry exposition?
Which password policy is more secure: one password of length 9 vs. two passwords each of length 8?
Can making a creature unable to attack, after it has been assigned as an attacker, remove it from combat?
how to acknowledge an embarrasing job interview, now that I work directly with the interviewer?
How can animals be objects of ethics without being subjects as well?
My cat mixes up the floors in my building. How can I help him?
It took me a lot of time to make this, pls like. (YouTube Comments #1)
How to remove lines through the legend markers in ListPlot?
Intern applicant asking for compensation equivalent to that of permanent employee
Error in a formula field
What is the most triangles you can make from a capital "H" and 3 straight lines?
Can an insurance company drop you after receiving a bill and refusing to pay?
What kind of hardware implements Fourier transform?
Why do stocks necessarily drop during a recession?
How to deal with an incendiary email that was recalled
A starship is travelling at 0.9c and collides with a small rock. Will it leave a clean hole through, or will more happen?
Lick explanation
Indirectly access environment variable
What is better: yes / no radio, or simple checkbox?
Magento 2 : Call Helper Without Using __construct in Own Module
Mandatory Helper class for module admin panel settingsHow to override core helper in magento 2?magento 2 get product sale count using custom moduleMagento 2 : How can I call helper function on override blockMagento 2 : How can I call helper function on override product list blockHow To Override Custom Module Helper in Magento 2Magento 2 Custom New Block without moduleHow to call getReviewsCollection() function from MagentoReviewBlockProductView?Call block function from helperMagento 2 Create dynamic array From different Model Collection to use in multi select in grid
I have created a new module and override the
MagentoCatalogBlockProductViewDescription
function using preference.
In this module we create new helper located in
Custom_Hello/Helper/Data.php
Then how to call this helper in
Custom_Hello/Block/Product/View/Description.php
If we use __construct got some error.
public function __construct(CustomHelloHelperData $helper)
{
$this->helper = $helper;
}
Anyone helpme
magento2 helper
add a comment |
I have created a new module and override the
MagentoCatalogBlockProductViewDescription
function using preference.
In this module we create new helper located in
Custom_Hello/Helper/Data.php
Then how to call this helper in
Custom_Hello/Block/Product/View/Description.php
If we use __construct got some error.
public function __construct(CustomHelloHelperData $helper)
{
$this->helper = $helper;
}
Anyone helpme
magento2 helper
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago
add a comment |
I have created a new module and override the
MagentoCatalogBlockProductViewDescription
function using preference.
In this module we create new helper located in
Custom_Hello/Helper/Data.php
Then how to call this helper in
Custom_Hello/Block/Product/View/Description.php
If we use __construct got some error.
public function __construct(CustomHelloHelperData $helper)
{
$this->helper = $helper;
}
Anyone helpme
magento2 helper
I have created a new module and override the
MagentoCatalogBlockProductViewDescription
function using preference.
In this module we create new helper located in
Custom_Hello/Helper/Data.php
Then how to call this helper in
Custom_Hello/Block/Product/View/Description.php
If we use __construct got some error.
public function __construct(CustomHelloHelperData $helper)
{
$this->helper = $helper;
}
Anyone helpme
magento2 helper
magento2 helper
edited 1 hour ago
Dhiren Vasoya
4,32951842
4,32951842
asked 1 hour ago
Soundararajan mSoundararajan m
413
413
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago
add a comment |
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago
add a comment |
4 Answers
4
active
oldest
votes
You can add your custom helper in constructor, but as this method is present in the class you're extending then you'd pass the right parameters in it, not just your helper
class Description extends MagentoCatalogBlockProductViewDescription
You are extending MagentoCatalogBlockProductViewDescription so let's see constructor in this class (in 2.3 version, you can check this in your project for other version, if that's the case)
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
So, in your class you'd pass that $context & $registry parameters. You can do that this way
public function __construct(
CustomHelloHelperData $helper,
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->helper = $helper;
parent::__construct($context, $registry, $data);
}
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
add a comment |
I got the solution. If we use following way
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
CustomHelloHelperData $dataHelper,
array $data = []
) {
parent::__construct($context, $registry, $data);
$this->_dataHelper = $dataHelper;
}
Answered at same time :)
– Raul Sanchez
30 mins ago
add a comment |
You can use directly without contructor
$this->helper('CompanyNameModuleNameHelperData')->yourfunctionname();
New contributor
add a comment |
In Custom_Hello/Block/Product/View/Description.php
File
protected $helper;
public function __construct(
MagentoCatalogBlockProductContext $context,
CustomHelloHelperData $helper
array $data = []
)
{
$this->helper= $heper;
parent::__construct($context, $data);
}
And You Can Call Your Helper Function Like this
$this->helper->yourFunctionName()
add a comment |
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%2f264051%2fmagento-2-call-helper-without-using-construct-in-own-module%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can add your custom helper in constructor, but as this method is present in the class you're extending then you'd pass the right parameters in it, not just your helper
class Description extends MagentoCatalogBlockProductViewDescription
You are extending MagentoCatalogBlockProductViewDescription so let's see constructor in this class (in 2.3 version, you can check this in your project for other version, if that's the case)
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
So, in your class you'd pass that $context & $registry parameters. You can do that this way
public function __construct(
CustomHelloHelperData $helper,
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->helper = $helper;
parent::__construct($context, $registry, $data);
}
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
add a comment |
You can add your custom helper in constructor, but as this method is present in the class you're extending then you'd pass the right parameters in it, not just your helper
class Description extends MagentoCatalogBlockProductViewDescription
You are extending MagentoCatalogBlockProductViewDescription so let's see constructor in this class (in 2.3 version, you can check this in your project for other version, if that's the case)
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
So, in your class you'd pass that $context & $registry parameters. You can do that this way
public function __construct(
CustomHelloHelperData $helper,
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->helper = $helper;
parent::__construct($context, $registry, $data);
}
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
add a comment |
You can add your custom helper in constructor, but as this method is present in the class you're extending then you'd pass the right parameters in it, not just your helper
class Description extends MagentoCatalogBlockProductViewDescription
You are extending MagentoCatalogBlockProductViewDescription so let's see constructor in this class (in 2.3 version, you can check this in your project for other version, if that's the case)
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
So, in your class you'd pass that $context & $registry parameters. You can do that this way
public function __construct(
CustomHelloHelperData $helper,
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->helper = $helper;
parent::__construct($context, $registry, $data);
}
You can add your custom helper in constructor, but as this method is present in the class you're extending then you'd pass the right parameters in it, not just your helper
class Description extends MagentoCatalogBlockProductViewDescription
You are extending MagentoCatalogBlockProductViewDescription so let's see constructor in this class (in 2.3 version, you can check this in your project for other version, if that's the case)
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->_coreRegistry = $registry;
parent::__construct($context, $data);
}
So, in your class you'd pass that $context & $registry parameters. You can do that this way
public function __construct(
CustomHelloHelperData $helper,
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
array $data = []
) {
$this->helper = $helper;
parent::__construct($context, $registry, $data);
}
answered 33 mins ago
Raul SanchezRaul Sanchez
2,09131235
2,09131235
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
add a comment |
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
thanks for your comments. Already got the solution and again thanks
– Soundararajan m
30 mins ago
add a comment |
I got the solution. If we use following way
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
CustomHelloHelperData $dataHelper,
array $data = []
) {
parent::__construct($context, $registry, $data);
$this->_dataHelper = $dataHelper;
}
Answered at same time :)
– Raul Sanchez
30 mins ago
add a comment |
I got the solution. If we use following way
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
CustomHelloHelperData $dataHelper,
array $data = []
) {
parent::__construct($context, $registry, $data);
$this->_dataHelper = $dataHelper;
}
Answered at same time :)
– Raul Sanchez
30 mins ago
add a comment |
I got the solution. If we use following way
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
CustomHelloHelperData $dataHelper,
array $data = []
) {
parent::__construct($context, $registry, $data);
$this->_dataHelper = $dataHelper;
}
I got the solution. If we use following way
public function __construct(
MagentoFrameworkViewElementTemplateContext $context,
MagentoFrameworkRegistry $registry,
CustomHelloHelperData $dataHelper,
array $data = []
) {
parent::__construct($context, $registry, $data);
$this->_dataHelper = $dataHelper;
}
answered 33 mins ago
Soundararajan mSoundararajan m
413
413
Answered at same time :)
– Raul Sanchez
30 mins ago
add a comment |
Answered at same time :)
– Raul Sanchez
30 mins ago
Answered at same time :)
– Raul Sanchez
30 mins ago
Answered at same time :)
– Raul Sanchez
30 mins ago
add a comment |
You can use directly without contructor
$this->helper('CompanyNameModuleNameHelperData')->yourfunctionname();
New contributor
add a comment |
You can use directly without contructor
$this->helper('CompanyNameModuleNameHelperData')->yourfunctionname();
New contributor
add a comment |
You can use directly without contructor
$this->helper('CompanyNameModuleNameHelperData')->yourfunctionname();
New contributor
You can use directly without contructor
$this->helper('CompanyNameModuleNameHelperData')->yourfunctionname();
New contributor
New contributor
answered 16 mins ago
Mitrajsinh vaghelaMitrajsinh vaghela
664
664
New contributor
New contributor
add a comment |
add a comment |
In Custom_Hello/Block/Product/View/Description.php
File
protected $helper;
public function __construct(
MagentoCatalogBlockProductContext $context,
CustomHelloHelperData $helper
array $data = []
)
{
$this->helper= $heper;
parent::__construct($context, $data);
}
And You Can Call Your Helper Function Like this
$this->helper->yourFunctionName()
add a comment |
In Custom_Hello/Block/Product/View/Description.php
File
protected $helper;
public function __construct(
MagentoCatalogBlockProductContext $context,
CustomHelloHelperData $helper
array $data = []
)
{
$this->helper= $heper;
parent::__construct($context, $data);
}
And You Can Call Your Helper Function Like this
$this->helper->yourFunctionName()
add a comment |
In Custom_Hello/Block/Product/View/Description.php
File
protected $helper;
public function __construct(
MagentoCatalogBlockProductContext $context,
CustomHelloHelperData $helper
array $data = []
)
{
$this->helper= $heper;
parent::__construct($context, $data);
}
And You Can Call Your Helper Function Like this
$this->helper->yourFunctionName()
In Custom_Hello/Block/Product/View/Description.php
File
protected $helper;
public function __construct(
MagentoCatalogBlockProductContext $context,
CustomHelloHelperData $helper
array $data = []
)
{
$this->helper= $heper;
parent::__construct($context, $data);
}
And You Can Call Your Helper Function Like this
$this->helper->yourFunctionName()
answered 35 mins ago
Ronak RathodRonak Rathod
1497
1497
add a comment |
add a comment |
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%2f264051%2fmagento-2-call-helper-without-using-construct-in-own-module%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
you can use object manager method into this case, As I know that is not peoper method.
– Dhiren Vasoya
1 hour ago
I'm new in magento. But using plugin we got solution then using this way error
– Soundararajan m
1 hour ago
Could you provide the error you are receiving? The way you are injecting it is the proper approach so if we can resolve the error that would be best.
– rain2o
1 hour ago
Fatal error: Uncaught Error: Call to a member function dispatch() on null in /var/www/html/magento2/lib/internal/Magento/Framework/View/Element/AbstractBlock.php:652 Stack trace: #0 /var/www/html/magento2/lib/internal/Magento/Framework/Interception/Interceptor.php(58): MagentoFrameworkViewElementAbstractBlock->toHtml() #1
– Soundararajan m
1 hour ago