This is the final part of the article about using FastReport.Net in conjunction with a PHP application.
In previous articles, we looked at the way to create a server part on ASP.Net Core. Let me remind you that it allows you to get a report display, a report designer display with a report loaded into it for editing, to download reports in a given format.
Now we have to implement a php application. To do this, you must have a web server installed, for example, Apache and PHP installed on it.
We will not consider the principles of creating php applications as part of this article.
Let's just decide on the structure of the pages. We need 3 web page templates:
• Home - displays a web report;
• Designer - displays the report designer;
• Downloads - button to download the report.
Each page will have the same title with the menu. Therefore, it makes sense to put it in a separate file - header.php. Let's create it in the htdocs folder in the directory of preinstalled Apache.
Also, on each page there will be a drop-down list with reports and an action button. This module is also moved to a separate file - reportslist:
This uses the content retrieval method to load the list of reports in json format. The link points to the local debugging iis file, on which our server part is "raised". Next, using php code, we fill out the drop-down list using the data received from the server. The Get button launches the selected () function, which will be unique on each page.
We all know that usually the index.php file is used for the main page of a site. Let's create it.
The page template includes a headline and body. The title, as usual, includes a title, meta data, a link to styles. In the body of the page, we included files with a header and a drop-down list. Remember that the Get button in the reportslist.php module calls the Get () function.
The stylesheet is also quite simple stylesite.css:
Let's start our web server and look at the index page:
We have a drop-down list and a button. Select the report and press the button:
As a result, we get a web report object. Moreover, the buttons on the toolbar have not lost functionality - you can export to the desired format and print.
Now we implement the Dedigner.php page. Create it in the same directory with index.php:
As you can see, the html page template is no different from index.php. The only difference is in the Get () method. We get the name of the report selected in the drop-down list. Then, insert the iframe with a reference to the Design method on the backend. In the parameter we pass the name of the report. As a result, we will see a page similar to index:
But, if we click on the Get () button:
... we get a designer with a loaded report template. We can edit it and save:
The saved message in the green frame will tell us that the report is saved.
It remains to implement the third page - Downloads. Create the file downloads.php:
The page template in addition to the drop-down list contains two radio buttons: pdf, html. These are the two types of exports that we implemented on the backend. The Get () method this time is significantly different. Instead of the name, we get the index of the report selected in the drop-down list. In the script, we create the <a> tag and set the link to the backend, where using WebApi we get the report on the index in the specified format. After forming the link, we immediately click on it programmatically. Thus we download the file. Here's how it works:
Click Get button. And we get the file:
You could display the report in the WebReport object, as on the first page, and then do the export. The Downloads page shows an alternative method of obtaining report export - directly from the server.
This concludes the 3-part article on working with FastReport.Net reports from a PHP application.