1

I have defined a constant in a custom helper in module A. I want to call it an admin method from a custom controller from a custom module B.

This is my custom helper class from module A:

Mymodule_Mynamespace_Helper_MyClass

Getting my constant value from this class in another module (B) , in a block or model, like Mymodule_Mynamespace_Helper_MyClass::TEST_CONSTANT, it works . Doing the same thing in a controller method:

public function myMethodAction(){
     echo Mymodule_Mynamespace_Helper_MyClass::TEST_CONSTANT
}

I am getting this error message: Error: Undefined class constant Any clue why ? Thank you in advance

1 Answer 1

0

As such there is no restriction to call constant in controller. The code you are using in block, helper, model can be use in Controller. Might be your code have some issue and to debug you can try below steps.

I tried same scenario it's working fine at my end. You can try below this:

$helper=Mage::helper('mynamespace/myclass');

first check if the class you are getting is correct here for not by using this:

echo get_class($helper);

if the class is correct then check constant is defined in the class name received from last code or not

if exist then try below code to get value

echo ($helper::TEST_CONSTANT);

Hope it might help you to debug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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