Question

I have a plugin for Joomla 2.5 which shows error messages like this:

Article Rating: Invalid Rating: 10

You already rated this Article today!

And I'm creating another plugin similar to this one, but don't know how to show these kind of messages. I think is messages are taken from: en-GB.com_content.ini

This is the plugin I'm using as reference: http://pastebin.com/hcpczq5C

Thanks in advance.

Was it helpful?

Solution

Line 186 of the file that you reference sets the task for the form:

 $html .= '<input type="hidden" name="task" value="article.vote" />';

This task along with the option set on line 188:

 $html .= '<input type="hidden" name="option" value="com_content" />';

Together these mean that the generated form are submitted to the com_content component and runs the vote function in the article controller.

If you have a look at this controller (components/com_content/controllers/article.php), you will find a simple call to the model to try to store the vote and then it sets a redirect to a url with either the success or failure method. $this->setRedirect() works in a controller, so that is how they set the message.

This means for you that you either have to set up a component as an end point and mimic how they save the information (assuming you aren't rating an article, which you could then just use this method) or you have to handle the save in the plugin (not really recommended, but can be made to work).

If you handle saving in your own plugin, you would have to use a more generic method for adding a message to the page:

JFactory::getApplication()->enqueueMessage('Message goes here.');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top