Creating Links to Reports in Web Pages
There are several options for creating links to reportico reports.
To embed links you can include them in your yii2 views and pages. You can either embed the HTML for the links or use the Yii2 HTML::linkAction helper function to generate the link more easily. Example links are given below.
When running reports for projects that you have password protected, you will need to pass that password through the project_password parameter
Create a Link to Report Output
Firstly you may want to link to Reportico in a new browser/tab.
You can create a link to a report output:-
echo Html::a( "Try this out...", Url::toRoute(['reportico/mode/execute', 'project' => 'northwind', 'project_password' => 'password', // Only necessary for password protected projects 'new_reportico_window' => 1, 'report' => 'salestotals.xml']), array("target" => "_blank")); which is the eqivalent to the HTML <a href="http://{yii2_app_url}/index.php/reportico/mode/execute?project=northwind&new_reportico_window=1&report=salestotals.xml">
Run it as an ajax request
To run as an ajax request and have the output appear in a popup div you need to include a div to present the report ( or a bootstrap modal box ) within your page. Then include some jQuery to handle the link click event and then pass the link url to the ajax call and render the results to the div.So create the link and include the "reportico_ajax_request" parameter set to 1 to tell reportico its an ajax call. Also because this page already uses bootstrap we pass reportico_bootstrap_preloaded=1 to tell Reportico not to load it again.
Also include a class or id on the link you can use to trigger the jQuery click on.
// Create modal window in HTML <?php Modal::begin([ 'id' => 'myModal', 'header' => 'Ajax Report', 'size' => 'modal-lg' ]); ?> <div id='modalcontent'></div> <?php Modal::end(); ?> // Register click event to trigger AJAX call <?php $this->registerJs( " $(document).on('click', '#reportico_popup', function(event) { $('#myModal').modal('show') ; $('#modalcontent').html('Please wait ..'); jQuery.ajax({ type: 'GET', url: jQuery(this).attr('href') }). done(function(html_form) { $('#modalcontent').html(html_form); reportico_initialise_page(); }); return false; });"); ?>
Also you can run a report criteria entry in a separate div just setting the controller route to reportico/mode/prepare.
Add a print button
Now you might want to add a print button, so add the parameter printable_html=1
echo Html::a( "Try this out...", Url::toRoute(['reportico/mode/execute', 'project' => 'northwind', 'new_reportico_window' => 1, 'printable_html' => 1, 'report' => 'salestotals.xml']), array("target" => "_blank")); which is the eqivalent to the HTML <a href="http://{yii2_app_url}/index.php/reportico/mode/execute?project=northwind&printable_html=1&new_reportico_window=1&report=salestotals.xml">
Generate a PDF/CSV Report
To link to a PDF or CSV just add "target_format=PDF" or "target_format=CSV" ..
echo Html::a( "Try this out...", Url::toRoute(['reportico/mode/execute', 'target_format' => "PDF", 'project' => 'northwind', 'report' => 'salestotals.xml']), array("target" => "_blank")); which is the eqivalent to the HTML <a href="http://{yii2_app_url}/index.php/reportico/mode/execute?project=northwind&target_format=PDF&report=salestotals.xml">
Create a link to a report menu
To link to a Menu use the menu action
echo Html::a( "Try this out...", Url::toRoute(['reportico/mode/menu', 'project' => 'northwind']), array("target" => "_blank")); which is the eqivalent to the HTML <a href="http://{yii2_app_url}/index.php/reportico/mode/menu?project=northwind&report=salestotals.xml">
Create a link to a report in criteria mode
To link to a report in criteria entry mode
echo Html::a( "Try this out...", Url::toRoute(['reportico/mode/prepare', 'project' => 'northwind', 'report' => 'salestotals.xml']), array("target" => "_blank")); which is the eqivalent to the HTML <a href="http://{yii2_app_url}/index.php/reportico/mode/prepare?project=northwind&report=salestotals.xml">