Developing a component frontend update function/Excel xlsx export
From Joomla! Documentation
Articles in this Series
21 Improved csv export
As explained in the previous chapters, Joomla usually displays data in html format. However, it does support other formats as well, including the 'raw' format meaning that in that case Joomla does not perform any layout operations at all for the data.
That is exactly the way to go for downloading an export file as generally we have to assume that such file just contains 'binary' data.
21.2 The changes
Again, have been updated to reflect version info. A new directory admin/button is created in this chapter, and therefore an additional admin/button/index.html placeholder file as well. helloworld.xml is updated accordingly.
In Joomla processing of a page begins with starting the concerning controller. To indicate that processing should yield raw data rather than an html page, the controller must receive the 'format=raw' input parameter. These parameter is typically provided by adding an hidden input tag to the form that starts the controller. Like:
<form action="index.php?option=com_helloworld" method="post" name="adminForm"> ... <input type="hidden" name="format" value="raw"/> </form>
The HelloWorld database items are handled from the HelloWorld admin page with form:
or its frontend counterpart. The available functions like create new item, delete an item or update an item are offered to the user as buttons above this form. Our export button is here as well.
Pushing a button typically navigates to another web form, like the edit form to update a particular item. These forms are in html format, so including the 'format=raw' input tag permanently to the above form definition file tmpl/default.php would cause a conflict for these functions.
This is almost the same file as the previous 'admin/controllers/helloexport.php' except that its name has been changed in view of Joomla rules. Joomla expects a controller for raw format to have a filename <controller>.raw.php, although the class name is still <component>Controller<controller>, so 'HelloWorldControllerHelloExport' in this case.
The big difference with the previous controller version is that the application does not need to be forcibly closed as Joomla now understands from the 'format=raw' tag that the controller yields a raw format layout and embedding in html is not required anymore.
The final statements
therefore have been removed as calling these functions will now be performed by Joomla in the standard way when the controller finishes the 'exportcsv' function.
21.3 Source files for this step
21.4 Testing the features of this step
- Perform the same test as in the previous section 20.4 , and verify that the export works as it did before.