Which message library to use? |
[eluser]victorche[/eluser]
Hello to @all! I am in a need of a global solution for my site. It is about displaying all kinds of messages/errors. I need a simple and nice solution and I came across 2 different libraries. The second one is written by @n0xie and is based on the first one. Here are the links: http://github.com/jeroenvdgulik/codeigniter-message/ - Written by n0xie http://codeigniter.com/wiki/Message/ - The original one, current version 2.1 My questions are... Which one is better, more flexible? I am using CI 2.0 and PHP5, so which one is ready for CI 2.0? Please, people who are using one of those... Give me a hint
[eluser]n0xie[/eluser]
Obviously I'm biased but I'll humour you. ;-) Depending on what you want my library can style individual messages via view partials. So for instance it will wrap all the 'notice' messages into a 'notice' div, all the 'error' messages into an error div and all the 'success' messages into a 'success' div. This is all done automatically by convention. See the example controller in my repository. I haven't tested my library extensively on CI2.0 but I suspect no difference in functionality.
[eluser]victorche[/eluser]
Thank you, @n0xie! Will give it a try... My question was how can I use it together with flashdata messages, I mean something as a small example. :]
[eluser]victorche[/eluser]
@n0xie, thanks! But anyway I can not solve this. First question is: What is the difference between Code: $this->message->display(); Code: // First setting the message after a login submit: Code: <div id="message"><?php echo $message; ?></div> So I tried to modify this code example like: Code: // Then if we have a message, display it:
[eluser]n0xie[/eluser]
Did you at least take a look at the example controller? Code: // Then if we have a message, display it:
[eluser]victorche[/eluser]
Thank you, @n0xie! I was doing almost the same, but... Code: $this->session->flashdata('message'); // Sometimes here i have both errors and messages ... So I am doing like: Code: $this->message->set($message); // Without specifying the msg type. And this way it is using the default wrapper from the config.
[eluser]victorche[/eluser]
By the way, there is a small error, I think... After line 163: Code: // does a default view partial exist? Code: // does a default view partial exist? Quote:The email field is required.In this case I have to do like: Code: $message[] = (validation_errors()) ? validation_errors() : $this->session->flashdata('message'); ![]() Maybe because ... Even an empty array makes the div visible? I think (I am a newbie in programming) there should be a check if the array is empty, or ... what? Can you give me one last hint about this? Thanks in advance!
[eluser]n0xie[/eluser]
For the first part of the question: it's not necessary in CodeIgniter to add the _view part when loading a view. The loader will look for the file with or without the _view part. For the second part I think I found your bug. The validation_errors() array returns 'something' even if there are no errors yet. I updated the Message Library to skip empty messages. Thanks for the bug report!
[eluser]victorche[/eluser]
[quote author="n0xie" date="1286285999"]For the first part of the question: it's not necessary in CodeIgniter to add the _view part when loading a view. The loader will look for the file with or without the _view part. For the second part I think I found your bug. The validation_errors() array returns 'something' even if there are no errors yet. I updated the Message Library to skip empty messages. Thanks for the bug report![/quote] Thanks, n0xie! Anyway... The first part, my config looks like this: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Quote:ErrorIf I make the change (as showed 2 posts above) it works perfectly. Do you mean that this check: Code: elseif (file_exists(APPPATH.'views/'.$this->message_folder.$this->message_view.'_view'.EXT)) I think this way, it will look for message_view_view.php, if in the config I am using: Code: $config['message_view'] = 'message_view'; // the library is making a check with .'_view', so i think this will be a problem? |
Welcome Guest, Not a member yet? Register Sign In |