CodeIgniter Forums
Store Notification Messages - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: Store Notification Messages (/showthread.php?tid=69405)



Store Notification Messages - chrismartinez99 - 11-16-2017

Hi,

Not sure if this is the best place to post this, but here goes.

I'd like to keep all of my applications notification messages in one spot for easier maintenance. Right now I've created a library Messages and store all of the messages as constants, so then I can refer to them as Message::ERROR_WITH_SUBMISSION in the code, for example.Is this an accepted way?

Or should I be adding these types of messages be added to the constants.php file?

How would you go about this?

Thank you in advance,
Chris


RE: Store Notification Messages - dave friend - 11-16-2017

IMO, the library is a better solution than using constants.php mostly because the library provides a clear separation of concerns. Even with the library I would probably use a separate file that contains the actual constant definitions.

An alternative approach might be to use a config file where the messages are accessed by using keys into the config array.