KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.

Pass data to view #1124

Closed paulo opened this topic on on Oct 10 - 9 comments

paulo commented on Oct 10

How can I do some php calculation in laravel report class and then pass them to the view and display them ? For instance, I will use Laravel-php to calculate the number of business dates taking into account weekends and stat holidays based on the employee province. I'd like to pass this info to the view. The view will show a report showing the hours worked <- this part is straight forward.

thank you!

KoolReport commented on Oct 11

Could you please share some of your code. I a little confuse with view of report with view of laravel. Those are different.

paulo commented on Oct 15

I have a function like the one below to give me the number of working days. I want to send this information to the view, so I can display there on the top. After this, I will show a simple report. Showing this report is not an issue. The issue is to pass the information from the function below to the view. thanks

function number_of_working_dates($from, $days) {
    $workingDays = [1, 2, 3, 4, 5]; # date format = N (1 = Monday, ...)
    $holidayDays = ['*-12-25', '*-01-01', '2013-12-24', '2013-12-25']; # variable and fixed holidays

    $from = new DateTime($from);
    $dates = [];
    $dates[] = $from->format('Y-m-d');
    while ($days) {
        $from->modify('+1 day');

        if (!in_array($from->format('N'), $workingDays)) continue;
        if (in_array($from->format('Y-m-d'), $holidayDays)) continue;
        if (in_array($from->format('*-m-d'), $holidayDays)) continue;

        $dates[] = $from->format('Y-m-d');
        $days--;
    }
    return $dates;
}
print_r( number_of_working_dates('2013-12-23', 3) );
paulo commented on Oct 17

Hi, did you have a chance to take a look at this? How can I pass data from the report class file to the report view ? thank you

KoolReport commented on Oct 17

You can pass any parameters to report, please follow this topics. In the view of your report, you still can use $this->params["your-param-name"]

paulo commented on Oct 18

thank you. I have been using this for sending to the report. Now, how can I access this param from the view? Can I just use {{$this->params["year"]}}

(using Laravel) thank you!

KoolReport commented on Oct 19

Please do not confuse between view of KoolReport and the view of laravel. The view of KoolReport is the file with .view.php located near the report class. The parameter $this->params["year"] is used inside the view of KoolReport. For the view of Laravel, please refer to laravel documentation to know how to pass param to the view.

paulo commented on Oct 30

Hi, I'be tried all this. My controller sends an id to the extends \koolreport\KoolReport class, but HOW can I send information from the class to the view?

The following works fine. I get the id of the user.

 function setup()
    {
        $id = $this->params["userId"]; //Auth::user()->id;
.....
}

Now, under the view "staffTimeLogManager.view.php' How can I display this amount? I've tried the following, nothing works: Staff id= <?php $this->params['userId'] ?>

staff 2=<?php $this->userID  ?>

staff 3= {{ userID }}

Thank you very much

KoolReport commented on Oct 30

In the view you should do:

staff id = <?php echo $this->params["userId"];  ?>
paulo commented on Oct 31

PERFECT! thank you!

KoolReport Is Free and Open-Source!

KoolReport is a professional php reporting framework which saves you tons of time to construct dynamic data report & dashboard.

  • Connect to various datasources such as MySQL, SQL Server, MongoDB or even from CSV or Excel file.
  • Contain series of powerful built-in data processes for your data manipulation.
  • Generate stunning charts and graphs to help you communicate data insights to your audiences effectively.
  • Integrate seamlessly with any php frameworks such as Laravel, CodeIgniter, Symfony.
Download Now and register our tutorials to get started!

Download KoolReport
help needed

None