simplyi Posted January 15, 2010 Share Posted January 15, 2010 Hi! I am interested to hear your opinion about the best place to keep messages that are displayed to users. It is better to keep them in one place and in a separate file. But will it be a bad approach if I keep messages in an array inside a Class or it is better to keep them in a text file, token delimited and open and read this file every time I need a message? What is your best practice? Thank you! class Messages { static public $messages = array( "invalidLogin" => "User name or password is not valid ", "welcome" => "Welcome ", "requireEmailAddress" => "Please provide email address" ); } Quote Link to comment https://forums.phpfreaks.com/topic/188585-what-is-the-best-place-to-keep-messages-displayed-to-users/ Share on other sites More sharing options...
Buddski Posted January 15, 2010 Share Posted January 15, 2010 Having them in a class as you have done isnt a bad way to go.. It gives you the freedom to change 1 file and not hunt around if you need to make changes to your messages. Quote Link to comment https://forums.phpfreaks.com/topic/188585-what-is-the-best-place-to-keep-messages-displayed-to-users/#findComment-995643 Share on other sites More sharing options...
laffin Posted January 15, 2010 Share Posted January 15, 2010 Only problem, is than the file becomes huge, and you will wasting memory on strings that arent on a particular page. so you may opt for creating different page strings and a general strings. Quote Link to comment https://forums.phpfreaks.com/topic/188585-what-is-the-best-place-to-keep-messages-displayed-to-users/#findComment-995662 Share on other sites More sharing options...
simplyi Posted January 15, 2010 Author Share Posted January 15, 2010 Thank you for your replies. Yes I agree. For different set of messages different arrays can be created. One for Database error message, one User Parameters validation messages and etc. But I think that a .propertry text file is still a better approach... and it is less error prone to modify property file. Quote Link to comment https://forums.phpfreaks.com/topic/188585-what-is-the-best-place-to-keep-messages-displayed-to-users/#findComment-995726 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.