I'm trying to define constant in an helper of my module :

here's my Data.php :

class Data extends AbstractHelper
    const base = "my/url";   

    public function getBase(){
        return $this->scopeConfig->getValue(


And my block, I create a function to get my constant :

public function getBaseAPIT(){
   return $this->_helper->getBase();

But the result of getBaseAPIT() is null. Where am I wrong ?

PS : to do this, I've follow that https://www.maximehuran.fr/creer-un-helper-sous-magento-2/

  • Can you please add in your question your database row which value you want to display. Jul 18, 2018 at 12:54
  • I want to display the value of the constant "base". "base" is my custom url, and I want to add it as the constant, so that i can access it from everywhere Jul 18, 2018 at 12:56
  • As per your logic It will return from core_config_data table row which have path value ""my/url" So i please check that this value is not null in your database Jul 18, 2018 at 13:00
  • I don't have this line in my database. How do I add it ? Jul 18, 2018 at 13:03
  • @Morgan Tartreau first you need to added entry in your database in core_config_data. Jul 18, 2018 at 13:44

1 Answer 1


For set to constant as per your logic need my/url value in database: add like below example:

      INSERT INTO `core_config_data` (`config_id`, `scope`, `scope_id`, 
      `path`, `value`) VALUES ('53069', 'default', '0', 'my/url', 

then you will get www.example.com by calling this function getBaseAPIT() }


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.