How to get messages as array instead of html block in magento - magento

at my template
checkout/cart.phtml
There is one line
echo $this->getMessagesBlock()->getGroupedHtml();
Which returns html block of messages like errors
How can I get this messages as array instead of entire HTML Block ?
thanks

In magento, there are 4 types of messages.
Error
Warning
Notice
Success
You can use following method to get all messages as a collection of array.
$this->getMessagesBlock()->getMessages();
If you specify the type of message that you need to retrieve inside getMessages(), you will get only that type of messages as an array. ie
$this->getMessagesBlock()->getMessages('error');
$this->getMessagesBlock()->getMessages('warning');
$this->getMessagesBlock()->getMessages('notice');
$this->getMessagesBlock()->getMessages('success');

Related

Thymeleaf: resolve most specific of multiple message codes

I have an array of possible i18n message codes. Lets call it codes. Let's assume it contains values
[most.specific, specific, default]
Let's assume the messages.properties contains messages for specific and default, but not for most.specific.
I would be happy to be able to write in my Thymeleaf template something like
#{${codes}}
to get a message for specific code (since it is the first one that is defined).
I need Thymeleaf to resolve the first available message code that is defined in messages file into a string, ignoring the other message codes.
How to do this concisely?

SweetAlert printing error messages from array

Can SweetAlert print error messages that are given to it from PHP via an array? If so, is there an example of this?
Specifically, can it read directly from a json_decode the actual error message to print?

Dingo APi error message

I am trying to render my mailable in the browser in order to check the content. However I'm getting this message {"message":"sha1() expects parameter 1 to be string, object given","status_code":500}
My code snippet
I am running Dingo/Api on my page as well an I think it's somehow connected with it.
Can you please give me the suggestion why am I getting this message instead of rendering mailable?
Thank you
We got this to work by assigning the mailable to a var first and then directly calling the render function on it, like so:
$mailable = new YourMailableName();
return $mailable->render();

System messages in Joomla 2.5 on success

I developed a component on backend, and now I faced a problem that I can't see a system message after data is updated. I suppose I had missed something like a message box or some code but still can't define exactly what it is. Can anybody tell me which data is necessary to get those messages?
// Get a handle to the Joomla! application object
$application = JFactory::getApplication();
// Add a message to the message queue
$application->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
/** Alternatively you may use chaining */
JFactory::getApplication()->enqueueMessage(JText::_('SOME_ERROR_OCCURRED'), 'error');
The second argument to the enqueueMessage function is the type of the message. The default is 'message', but 'error' results in a different style for the message. The message will be displayed in place of a special jdoc:include statement in your template. Place the following in your template at the location where you want messages to appear.
<jdoc:include type="message" />
Read more

If codeigniter model returns 0 rows, display custom error message. How to extend to a general case?

I have a variety of functions within my models which serve a different purpose.
One for example looks up the data for a given $_GET variable in the URL string.
I am trying to work out a way of displaying an error message if there is no matching row in the database due to url string manipulation for example.
My first idea was simply to return an error message (if there is an error) with each call to the function, then simply have an if statement whereby if there is an error, an error view is shown, and if not the normal view is shown..
Problem with this is that this function is called numerous times in my controller, and other similar functions are called throughout my code which need similar error handling..
I dont want millions of similar if/else statements all over my code to handle errors..
Anyone got any better ideas?
Cheers
Use the flashdata item of the session class. You can concatenate error messages and put them in the flashdata item to display.
my_function(){
// code that determines if there is an error returns => $error
if ($error)
{
// concat previous and current errors
$new_error = $this->session->flashdata('errors') . $error;
// replace 'errors' with newly concatenated errors
$this->session->set_flashdata('errors', $new_error);
}
}
This will keep track of all errors generated through each request and allow you to display a "list" of errors for that particular request.
echo $this->session->flashdata('errors');

Resources