I want to define constants to use in all my project. How to define constant or environment variables to access all over the project without any special declaration ?


Define the constant with const keyword as :

const PATH_EMAIL_IDENTITY = 'trans_email/ident_sales';

To call constant in the same file use : self::PATH_EMAIL_IDENTITY

To call the same constant in another file use : VendorName\ModuleName\Controller\FileName::PATH_EMAIL_IDENTITY

  • I don't want to call by refference, I just want to call directly as we call in codeigniter or in other frameworks like echo PATH_EMAIL_IDENTITY; Feb 19 '19 at 10:21

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.