Welcome Guest, Not a member yet? Register   Sign In
Global feedback array and helper to display feedback?
#1

[eluser]Unknown[/eluser]
So there are lots of instances while in a controller or model where I need to show one or more errors/notices or success/confirm messages to the user.

I'm thinking of having a global $feedback array and then creating a simple helper which adds to this array at runtime and has functions for outputting the feedback nicely in views or as JSON in the case of ajax requests.

So at controller or model level...
Code:
feedback('error','Login Invalid, Please try again');
...
feedback('success','Thanks, Application submitted successfully');

So in a controller function, these might be called one or multiple times - each time adding to the feedback array.

At the view level, I'd call something like

Code:
display_feedback()

Which would check the array and loop through displaying any error or success messages.

• I could also have a function for returning it as JSON in the case of ajax requests
• I could have a couple of flags in that feedback() function to tell it wither to notify me (developer) by email or perhaps log to a DB.



I know CI has inbuilt show_error and log_message functions but neither of those seem to fit the bill here. Or am I mistaken? is this approach a good idea or not?





Theme © iAndrew 2016 - Forum software by © MyBB