• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FlashNotice Helper - EZ to use and Sexy too

#1
[eluser]Andy Blackwell[/eluser]
Download it from the WIKI page
Preview Image

Time for me to contribute back to the community! So here's my first attempt...

For those that use or would like to use those one-time informational messages that display after an action of some type (like success, error, warning, info), I've made a helper for them.

Autoload the helper and now anywhere in your app you can add messages with this syntax:
Code:
FlashNotice::add('Your message goes here', 'error');
// the second parameter is an optional message type which can be
// any of the predefined values (info, success, warning, error)
// defaults to 'success'

Use those throughout your app and the helper stores them all in a Session var 'FlashNotice'

Then to diplay it in your view (preferably place this in a template header or something, so you only have to write it once)
Code:
FlashNotice::display();
// if there are any messages it will compile and display them,
// then destroy the Session var that stored them.
// otherwise it won't print anything to the page

I have created a default look and feel for the display. To use it, just include the folder with the Css and images, and include the stylesheet in your html.

I included an example of javascript code to utilize the close buttons on the box, and make the FlashNotice disappear from the page. You could also turn it into a modal box with a few tweaks if you wanted.

Hope some people find it useful.

As is, it's PHP5 only, since I used some things like private and static methods...sorry PHP4'ers!

Download it from the WIKI page

#2
[eluser]Crimp[/eluser]
Flashdata is supported in the latest CI Session library.

#3
[eluser]xwero[/eluser]
i like the idea of having a standard way to display flashdata/errors but when i looked at the code i saw quite a lot of html in the helper code. I would rather see the html in a view file.

As crimp pointed out flashdata is already a part of the stable code and most of the custom session classes have it too so maybe you should focus on the display of the messages. Focussing on the display you could not only write a helper for flashdata but also for the validation class.

#4
[eluser]Crimp[/eluser]
Consider also the built-in CI error handling, show_error(), that can be customized, error_general.php. The benefit of this is that you can call it anywhere.

#5
[eluser]Andy Blackwell[/eluser]
Thanks for the feedback!

I designed the Helper to be as easy to use as possible, and as decoupled from other code as possible as well. As it stands, you could even take this and use it in a non-CI site and it would work exactly the same with no changes. I don't like mixing html within my php code, but I thought that having a specific markup like this would allow a standard api for Css manipulation of the display.

I'll leave this first version in the WIKI, but I will try to incorporate the ideas here and make a version that can:
• utilize other session libraries (CI native from SVN, and OBsession)
• rely on the HTML markup from a view file/files (so the display isn't so rigid)
• tie into CI's debugging
• possibly a config file to set some options

The debugging feature is something a co-worker suggested as well, and could be turned on/off in the config file.

Anymore ideas/comments?! Let me know!

#6
[eluser]Référencement Google[/eluser]
[quote author="Andy Blackwell" date="1193620514"]• rely on the HTML markup from a view file/files (so the display isn't so rigid)[/quote]

I think the way to go is puting the Html in view, then you can change dynamically a CSS class in the markup depending on the message type. Then all the design should be in an external CSS file. Sample view:

Code:
<dl class="msg &lt;?=$msg_class?&gt;">
    <dt>The message title</dt>
    <dd>Here goes the full message.</dd>
<dl>

#7
[eluser]Andy Blackwell[/eluser]
Got a new version up (v1.1)

This one uses Code Igniter's session library and an external view file. It will work with CI v1.6 from SVN.

Let me know what you think!

Get FlashNotice v1.1 on the Wiki

#8
[eluser]Andy Blackwell[/eluser]
Here's some example jQuery code for closing the Notice using the buttons. Thanks to Roger for pointing out that I accidentally left the js example out of the v1.1 zip.

Code:
$(function(){
    // Flash Notice close button code
    $("#FlashNotice a.close").click( function(e){
        e.preventDefault();
        $("#FlashNotice").slideUp("slow", function() {
           $("#FlashNotice").remove();
        });
    });
});


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.