KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Passing variables to controller and view #1023

Open Stefan Dietl opened this topic on on Jul 31, 2019 - 5 comments

Stefan Dietl commented on Jul 31, 2019

If I take Your basic example "Sales by Customer". How could I pass some variables from the "index.php" to the controller and view class? To the controller I could pass them trough the constructor-function. But to the view? Thanks Stefan

David Winterburn commented on Aug 1, 2019

Hi Stefan,

You could set/access $this and $this->params (array type) in both the controller/setup file and the view file of a report. So a way to pass variables is:

//MyReport.php
$this->var1 = $var1;
$this->params["var2"] = $var2;

//MyReport.view.php
$var1 = $this->var1;
$var2 = $this->params["var2"];

Let us know if we understand your question correctly. Thanks!

Stefan Dietl commented on Aug 1, 2019

Thank You, works!

Julio Albuquerque commented on Sep 18, 2019

In my case I need to pass value from index.php to MyReport.php and then to MyReport.view.php. The code that is index.php is as follows:

<? php
require_once "MyReport.php";
$tab = $ _GET ['table'];
$cam = $ _GET ['field'];

$report = new MyReport;
$report-> run() -> render();

I need to pass $tab and $cam variables to MyReport.php and then to MyReport.view.php; How can I do this?

Julio Albuquerque commented on Sep 19, 2019

Ok, solved.

Josua Pérez commented on Dec 12, 2019

I get an error when accessing params on view, beacuse the property "params" is protected on the object. So, on the view, the code

<?php  echo $report->params["id"]  ?>

throws the error.

The same occurs for "dataSources" property, but fortunately we have a method dataSources("name") for accessing this array, and this doen't happen with the params array. What am I missing?

(note: $report is the object on views because I use blade extension)

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
None yet

None