如何使用Codeigniter视图在Jasper报告中传递参数

时间:2019-02-20 07:56:47

标签: php codeigniter jasper-reports

我已经使用PHPJasperXML库从codeigniter渲染了jasper报告。我想知道如何从我的角度将参数传递给该报告。我没有在$ is_active变量中获取值。即使选中了复选框,该值也始终为0。

我的视图

<div class="form-group mb-2 col-lg-6">
     <div class="custom-control custom-checkbox">
     <input class="custom-control-input" id="is-active" type="checkbox" name="is-active">
      <label class="custom-control-label pt-1" for="is-active">Is Active</label>
     </div>
</div>
<a href="<?php echo base_url()?>MyController/getReport" target="_blank"><button name="btn_report" id="btn_report" type="button">Report</button></a>

我的控制器

public function getReport()
{
    if ($this->input->post('is-active') == true) {
        $is_active = 1;
    } else {
        $is_active = 0;
    }
    $path=base_url()."Assets/reports/report.jrxml";
    $params=array($is_active);
    $this->mymodel->showReport($path,$params);
}

1 个答案:

答案 0 :(得分:0)

您确定代码可以用<form></form>包装吗?

<div class="form-group mb-2 col-lg-6">
     <div class="custom-control custom-checkbox">
     <input class="custom-control-input" id="is-active" type="checkbox" name="is-active">
      <label class="custom-control-label pt-1" for="is-active">Is Active</label>
     </div>
</div>
<a href="<?php echo base_url()?>MyController/getReport" target="_blank"><button name="btn_report" id="btn_report" type="button">Report</button></a>

尝试一下:

<form action="<?php echo base_url()?>MyController/getReport" method="post">
    <div class="form-group mb-2 col-lg-6">
         <div class="custom-control custom-checkbox">
         <input class="custom-control-input" id="is-active" type="checkbox" name="is-active">
          <label class="custom-control-label pt-1" for="is-active">Is Active</label>
         </div>
    </div>
    <input name="btn_report" id="btn_report" type="submit" value="Report"/>
</form>