• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User Alert Library

#1
Hi all! I'm a long-time user with many live CI3 projects. Managing libraries across them got to be almost as much work as each project, so I developed five "zero conf" libraries to add core functions I needed which could be dropped in and used without setup. I never got around to publishing them, but as I rewrite them for CI4 I'll be making them available.
See my first post for the Asset Loader. Now I give you the second library:

Tatter/Alerts - "Zero conf" user alerts for CodeIgniter 4

Basic usage:

1. Install: `> composer require tatter/alerts`
2. Load the helper file: `helper("tatter\alerts");`
3. Set an alert: `alert("success", "Widget updated.");`
4. Add the wrapper & alerts to your view: `alerts();`


I am eager for feedback, suggestions, and contributions - feel free to respond here or on GitHub (https://github.com/tattersoftware/codeigniter4-alerts).
Thanks for reading!
Reply

#2
Hi,

I may be totally wrong here because I have not touched CI4 and although I am excited I think I will have to do quite a bit of learning some new techniques and concepts before I could do anything other than a hobby site. So perhaps my misunderstanding it due to this being for CI4 and not for CI3.

However it appears you are echoing directly from a library. This does not seem right to me even if you are echoing a view that you have returned as a string. Only controllers should control output.

https://www.codeigniter.com/user_guide/o...pflow.html

Again, perhaps CI4 is different in this respect. But output should be done in a controller, not in a library.

I hope you do not mind me mentioning this and your code looks great. Also I hope I am not being CI4 ignorant.

Best wishes,

Paul
Reply

#3
Hi Paul, thanks for another reply! I didn’t realize that was looked down on, but likely is the same for CI4 as it was in CI3. Thankfully since my libraries tend to use helper functions to wrap library calls it is a pretty trivial change - I’ll give that a shot this evening. Also working in my favor is the fact that currently nobody is using this but me.
Reply

#4
Version 1.1.0 posted - taking notes from CI4's Pager class the Alerts library can now accept a renderer (or will fallback to default renderer service) and use that to return formatted template HTML/CSS. It doesn't look like anyone is using this, but notable change (hence 1.1.0 instead of 1.0.1) is the wrapping helper functions should now be output rather than simply called:
`alerts()` -> `echo alerts()`

Thanks for the suggestion @PaulD! I'll be making this same update to the Assets library as well.
Reply

#5
Version 2! Not really a big change but I moved configuration from the constructor to a Config file and replaced some of the functions in the helper with an actual Service. This change will break existing uses of the library, but version 2.0 should prevent Composer from auto-updating it. I don't think anyone is using this, but in case you do update from 1 => 2 just be sure to save any custom configs (app/Config/Alerts.php) and port them into a new config file using Alerts.php.example as a base.
And check out the third library if you haven't already: Traffic Tracking (https://forum.codeigniter.com/thread-73161.html)
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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