jasperphp错误传递参数 [英] jasperphp error passing parameters

查看:128
本文介绍了jasperphp错误传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jasper报告中,我有一个这样的SQL句子:

In a jasper report I have a sql sentence like this:

SELECT * FROM table $P!{my_where}

在我的php程序中,我用这种方式调用报告:

In my php program, I'm calling the report this way:

    JasperPHP::process(
        base_path() . '/app/reports/report.jasper', 
        false,
        array("pdf"),
        array("my_where" => "WHERE field = value"),
        \Config::get('database.connections.mysql')
        )->execute();

然后,这是错误信息:

错误的报告参数格式!

Wrong report param format!

这样做的方式很简单,我的意思是:

Doing it the simple way works, I mean:

在报告:

SELECT * FROM table WHERE $P!{field} = $P{value}

在PHP中:

    JasperPHP::process(
        base_path() . '/app/reports/report.jasper', 
        false,
        array("pdf"),
        array("field" => $my_field, "value" => $my_value),
        \Config::get('database.connections.mysql')
        )->execute();

问题是,我需要从几个字段动态构建一个where子句,所以,只传递一个where参数是必须的。

The thing is, I need to build a where clause dynamically from several fields, so, passing a only "where" parameter is a must.

任何想法?

推荐答案

解决:只需要双引号参数:

Solved: is just necessary to double quote the parameter:

$my_where = '"' .  $my_where . '"';

JasperPHP::process(
    base_path() . '/app/reports/report.jasper', 
    false,
    array("pdf"),
    array("my_where" => $my_where),
    \Config::get('database.connections.mysql')
    )->execute();

这篇关于jasperphp错误传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆