drtzb06222 2011-04-04 03:37
浏览 28
已采纳

在Codeigniter gchart帮助用法方面需要帮助

I followed the wiki artichle (http://codeigniter.com/wiki/gchart/revision/5312/) to practice google chart in my CI 2.0. But it doesn't work.

controller file: ci\application\helpers\mytest.php

$this->load->helper( 'gchart' );
$this->load->view('my_test');

view file: ci\application\helpers\my_test.php

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);
echo <<< EOS
     <img src="
        http://chart.apis.google.com/chart?
            cht=lc
            &chs=250x250
            &chd;:e{$encoded}
        "
        alt="line graph of some example data" />
EOS;

help file: ci\application\helpers\gchart_helper.php

// I do copied all the source code from the wiki url link above.

When I try to charted by CI. It showed error as this, Parse error: syntax error, unexpected ';' in C:\xampp\htdocs\demo\ci\application\views\my_test.php on line 54

Any thing wrong on my operation? I compared the extendedencode() from gchart_helper.php

function extendedencode($data, &$maxvalue='notspecified')

and extendedencode() from my_test.php

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue;);

Then I updated the extendedencode() line to this in my_test.php view file,

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), &maxvalue);

And try again, but still get this error below.

Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in C:\xampp\htdocs\demo\ci\application\views\my_test.php on line 54

Any help or comments are great appreciated.

[updated]

When I use the formated below, 

$encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6) &maxvalue);

showed another four error message.



Events List

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant maxvalue - assumed 'maxvalue'

Filename: views/my_test.php

Line Number: 54

A PHP Error was encountered

Severity: Warning

Message: max() [function.max]: When only one parameter is given, it must be an array

Filename: helpers/gchart_helper.php

Line Number: 49

A PHP Error was encountered

Severity: Warning

Message: Division by zero

Filename: helpers/gchart_helper.php

Line Number: 55

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: encoded

Filename: views/my_test.php

Line Number: 61

[Updated against Frank's suggestion]

There are still two errors occurred below,

A PHP Error was encountered

Severity: Notice

Message: Undefined offset: 64

Filename: helpers/gchart_helper.php

Line Number: 65  // code line: $ret .= $grid[$x].$grid[$y];


A PHP Error was encountered

Severity: Notice

Message: Undefined variable: encoded

Filename: views/my_test.php

Line Number: 61 // code line: &chd;:e{$encoded}
  • 写回答

2条回答 默认 最新

  • duanjiaopi8218 2011-04-04 04:04
    关注

    Alex's answer isn't syntactically correct. Try:

    $encoded_data = extendedencode(array(0, 1, 2, 3, 4, 5, 6), $maxvalue);
    

    The & in the function documentation just tells you that your variable will be used by reference. You shouldn't (and in fact cannot) include the & when you call the function. In older versions of PHP, there was a feature called call-time pass by reference, in which you'd use syntax like that, but it's disallowed in recent versions.

    Edit:

    Regarding one of the additional errors you've listed: as the error says, there's no $encoded var in the code you've shown us. Try replacing &chd;:e{$encoded} with &chd;:e{$encoded_data} -- I'm guessing that might be what you intended.

    A sloppy method of silencing the final error would be to replace $ret .= $grid[$x].$grid[$y]; with $ret .= @$grid[$x].@$grid[$y];. Without additional context for the code in play there, it's hard to say what the actual root issue is there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办